2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtkmain.h>
29 #include <gtk/gtkmenu.h>
30 #include <gtk/gtkmenuitem.h>
31 #include <gtk/gtkitemfactory.h>
32 #include <gtk/gtkcheckmenuitem.h>
33 #include <gtk/gtkoptionmenu.h>
34 #include <gtk/gtkwidget.h>
35 #include <gtk/gtkclist.h>
36 #include <gtk/gtkctree.h>
37 #include <gtk/gtkvpaned.h>
38 #include <gtk/gtkentry.h>
39 #include <gtk/gtkeditable.h>
40 #include <gtk/gtkwindow.h>
41 #include <gtk/gtksignal.h>
42 #include <gtk/gtkvbox.h>
43 #include <gtk/gtkcontainer.h>
44 #include <gtk/gtkhandlebox.h>
45 #include <gtk/gtktoolbar.h>
46 #include <gtk/gtktable.h>
47 #include <gtk/gtkhbox.h>
48 #include <gtk/gtklabel.h>
49 #include <gtk/gtkscrolledwindow.h>
50 #include <gtk/gtkthemes.h>
51 #include <gtk/gtkdnd.h>
58 /* #include <sys/utsname.h> */
64 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
74 #include "mainwindow.h"
76 #include "addressbook.h"
77 #include "folderview.h"
82 #include "customheader.h"
83 #include "prefs_common.h"
84 #include "prefs_account.h"
87 #include "procheader.h"
89 #include "statusbar.h"
96 #include "alertpanel.h"
97 #include "manage_window.h"
98 #include "gtkshruler.h"
100 #include "addr_compl.h"
101 #include "quote_fmt.h"
102 #include "template.h"
105 # include "rfc2015.h"
115 #define N_ATTACH_COLS 3
117 #define B64_LINE_SIZE 57
118 #define B64_BUFFSIZE 77
120 #define MAX_REFERENCES_LEN 999
122 static GdkColor quote_color = {0, 0, 0, 0xbfff};
124 static GList *compose_list = NULL;
126 static Compose *compose_create (PrefsAccount *account,
128 static void compose_toolbar_create (Compose *compose,
129 GtkWidget *container);
130 static GtkWidget *compose_account_option_menu_create
132 static void compose_set_template_menu (Compose *compose);
133 static void compose_destroy (Compose *compose);
135 static gint compose_parse_header (Compose *compose,
137 static gchar *compose_parse_references (const gchar *ref,
140 static gchar *compose_quote_fmt (Compose *compose,
145 static void compose_reply_set_entry (Compose *compose,
150 followup_and_reply_to);
151 static void compose_reedit_set_entry (Compose *compose,
153 static void compose_insert_sig (Compose *compose);
154 static void compose_insert_file (Compose *compose,
156 static void compose_attach_append (Compose *compose,
158 ContentType cnttype);
159 static void compose_attach_append_with_type(Compose *compose,
162 ContentType cnttype);
163 static void compose_wrap_line (Compose *compose);
164 static void compose_wrap_line_all (Compose *compose);
165 static void compose_set_title (Compose *compose);
167 static PrefsAccount *compose_current_mail_account(void);
168 /* static gint compose_send (Compose *compose); */
169 static gint compose_write_to_file (Compose *compose,
172 static gint compose_write_body_to_file (Compose *compose,
174 static gint compose_save_to_outbox (Compose *compose,
176 static gint compose_remove_reedit_target (Compose *compose);
177 static gint compose_queue (Compose *compose,
180 static void compose_write_attach (Compose *compose,
182 static gint compose_write_headers (Compose *compose,
184 const gchar *charset,
185 EncodingType encoding,
188 static void compose_convert_header (gchar *dest,
192 static void compose_generate_msgid (Compose *compose,
196 static void compose_attach_info_free (AttachInfo *ainfo);
197 static void compose_attach_remove_selected (Compose *compose);
199 static void compose_attach_property (Compose *compose);
200 static void compose_attach_property_create (gboolean *cancelled);
201 static void attach_property_ok (GtkWidget *widget,
202 gboolean *cancelled);
203 static void attach_property_cancel (GtkWidget *widget,
204 gboolean *cancelled);
205 static gint attach_property_delete_event (GtkWidget *widget,
207 gboolean *cancelled);
208 static void attach_property_key_pressed (GtkWidget *widget,
210 gboolean *cancelled);
212 static void compose_exec_ext_editor (Compose *compose);
213 static gint compose_exec_ext_editor_real (const gchar *file);
214 static gboolean compose_ext_editor_kill (Compose *compose);
215 static void compose_input_cb (gpointer data,
217 GdkInputCondition condition);
218 static void compose_set_ext_editor_sensitive (Compose *compose,
221 static gint calc_cursor_xpos (GtkSText *text,
225 static void compose_create_header_entry (Compose *compose);
226 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
228 /* callback functions */
230 static gboolean compose_edit_size_alloc (GtkEditable *widget,
231 GtkAllocation *allocation,
232 GtkSHRuler *shruler);
234 static void toolbar_send_cb (GtkWidget *widget,
236 static void toolbar_send_later_cb (GtkWidget *widget,
238 static void toolbar_draft_cb (GtkWidget *widget,
240 static void toolbar_insert_cb (GtkWidget *widget,
242 static void toolbar_attach_cb (GtkWidget *widget,
244 static void toolbar_sig_cb (GtkWidget *widget,
246 static void toolbar_ext_editor_cb (GtkWidget *widget,
248 static void toolbar_linewrap_cb (GtkWidget *widget,
250 static void toolbar_address_cb (GtkWidget *widget,
254 static void select_account(Compose * compose, PrefsAccount * ac);
255 static void account_activated (GtkMenuItem *menuitem,
258 static void attach_selected (GtkCList *clist,
263 static void attach_button_pressed (GtkWidget *widget,
264 GdkEventButton *event,
266 static void attach_key_pressed (GtkWidget *widget,
270 static void compose_send_cb (gpointer data,
273 static void compose_send_later_cb (gpointer data,
277 static void compose_draft_cb (gpointer data,
281 static void compose_attach_cb (gpointer data,
284 static void compose_insert_file_cb (gpointer data,
288 static void compose_close_cb (gpointer data,
292 static void compose_address_cb (gpointer data,
295 static void compose_template_activate_cb(GtkWidget *widget,
298 static void compose_ext_editor_cb (gpointer data,
302 static gint compose_delete_cb (GtkWidget *widget,
305 static void compose_destroy_cb (GtkWidget *widget,
308 static void compose_cut_cb (Compose *compose);
309 static void compose_copy_cb (Compose *compose);
310 static void compose_paste_cb (Compose *compose);
311 static void compose_allsel_cb (Compose *compose);
313 static void compose_grab_focus_cb (GtkWidget *widget,
316 static void compose_changed_cb (GtkEditable *editable,
318 static void compose_button_press_cb (GtkWidget *widget,
319 GdkEventButton *event,
322 static void compose_key_press_cb (GtkWidget *widget,
327 static void compose_toggle_to_cb (gpointer data,
330 static void compose_toggle_cc_cb (gpointer data,
333 static void compose_toggle_bcc_cb (gpointer data,
336 static void compose_toggle_replyto_cb (gpointer data,
339 static void compose_toggle_followupto_cb(gpointer data,
342 static void compose_toggle_attach_cb (gpointer data,
345 static void compose_toggle_ruler_cb (gpointer data,
349 static void compose_toggle_sign_cb (gpointer data,
352 static void compose_toggle_encrypt_cb (gpointer data,
356 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
359 static void compose_attach_drag_received_cb (GtkWidget *widget,
360 GdkDragContext *drag_context,
363 GtkSelectionData *data,
367 static void compose_insert_drag_received_cb (GtkWidget *widget,
368 GdkDragContext *drag_context,
371 GtkSelectionData *data,
376 static void to_activated (GtkWidget *widget,
378 static void newsgroups_activated (GtkWidget *widget,
380 static void subject_activated (GtkWidget *widget,
382 static void cc_activated (GtkWidget *widget,
384 static void bcc_activated (GtkWidget *widget,
386 static void replyto_activated (GtkWidget *widget,
388 static void followupto_activated (GtkWidget *widget,
390 static void compose_attach_parts(Compose * compose,
393 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
395 gboolean ignore_replyto,
396 gboolean followup_and_reply_to);
398 void compose_headerentry_changed_cb (GtkWidget *entry,
399 compose_headerentry *headerentry);
400 void compose_headerentry_key_press_event_cb (GtkWidget *entry,
402 compose_headerentry *headerentry);
404 Compose * compose_generic_new (PrefsAccount *account,
408 static GtkItemFactoryEntry compose_popup_entries[] =
410 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
411 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
412 {N_("/---"), NULL, NULL, 0, "<Separator>"},
413 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
416 static GtkItemFactoryEntry compose_entries[] =
418 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
419 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
420 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
421 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
422 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
423 {N_("/_File/_Close"), "<alt>W", compose_close_cb, 0, NULL},
425 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
426 {N_("/_Edit/_Undo"), "<control>Z", NULL, 0, NULL},
427 {N_("/_Edit/_Redo"), "<control>Y", NULL, 0, NULL},
428 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
429 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
430 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
431 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
432 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
433 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
434 {N_("/_Edit/_Wrap current paragraph"), "<alt>L", compose_wrap_line, 0, NULL},
435 {N_("/_Edit/Wrap all long _lines"),
436 "<shift><alt>L", compose_wrap_line_all, 0, NULL},
437 {N_("/_Edit/Edit with e_xternal editor"),
438 "<alt>X", compose_ext_editor_cb, 0, NULL},
440 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
441 {N_("/_Message/_Send"), "<control>Return",
442 compose_send_cb, 0, NULL},
443 {N_("/_Message/Send _later"), "<shift><alt>S",
444 compose_send_later_cb, 0, NULL},
445 {N_("/_Message/Save to _draft folder"),
446 "<alt>D", compose_draft_cb, 0, NULL},
447 #if 0 /* NEW COMPOSE GUI */
448 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
449 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
450 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
451 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
452 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
453 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
454 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
455 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
456 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
459 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
460 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
461 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
462 #endif /* USE_GPGME */
463 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
464 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
465 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
466 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
467 {N_("/_Tool/_Address book"), "<alt>A", compose_address_cb , 0, NULL},
468 {N_("/_Tool/_Template"), NULL, NULL, 0, "<Branch>"},
469 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
470 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
473 static GtkTargetEntry compose_mime_types[] =
475 {"text/uri-list", 0, 0}
478 Compose * compose_new(PrefsAccount *account)
480 return compose_generic_new(account, NULL, NULL);
483 Compose * compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
487 GtkItemFactory *ifactory;
489 c = compose_generic_new(account, NULL, NULL);
491 filename = procmsg_get_message_file(msginfo);
492 if (filename == NULL)
495 c->bounce_filename = filename;
497 if (msginfo->subject)
498 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
500 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
502 compose_quote_fmt(c, msginfo, "%M", NULL);
503 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
505 ifactory = gtk_item_factory_from_widget(c->popupmenu);
506 menu_set_sensitive(ifactory, "/Add...", FALSE);
507 menu_set_sensitive(ifactory, "/Remove", FALSE);
508 menu_set_sensitive(ifactory, "/Property...", FALSE);
510 ifactory = gtk_item_factory_from_widget(c->menubar);
511 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
512 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
513 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
514 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
515 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
516 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
517 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
518 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
520 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
521 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
523 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
524 menu_set_sensitive(ifactory, "/Tool/Template", FALSE);
526 gtk_widget_set_sensitive(c->insert_btn, FALSE);
527 gtk_widget_set_sensitive(c->attach_btn, FALSE);
528 gtk_widget_set_sensitive(c->sig_btn, FALSE);
529 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
530 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
535 Compose * compose_new_with_recipient(PrefsAccount *account, const gchar *to)
537 return compose_generic_new(account, to, NULL);
540 Compose * compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
542 return compose_generic_new(account, NULL, item);
545 static void set_compose_entries(Compose * compose, const gchar * mailto)
547 gchar * subject = NULL;
556 Xstrdup_a(tmp_mailto, mailto, return);
560 p = strchr(cur, '?');
572 p = strchr(cur, '=');
580 p = strchr(cur, '&');
587 if (g_strcasecmp(field, "subject")==0) {
588 Xstrdup_a(subject, value, );
590 decode_uri(subject, value);
592 else if (g_strcasecmp(field, "cc")==0)
594 else if (g_strcasecmp(field, "bcc")==0)
596 else if (g_strcasecmp(field, "body")==0) {
597 Xstrdup_a(body, value, );
599 decode_uri(body, value);
605 compose_entry_append(compose, to, COMPOSE_TO);
607 gtk_widget_grab_focus(compose->text);
612 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
614 compose_entry_append(compose, cc, COMPOSE_CC);
616 compose_entry_append(compose, bcc, COMPOSE_BCC);
618 gtk_stext_insert(GTK_STEXT(compose->text),
619 NULL, NULL, NULL, body, -1);
620 gtk_stext_insert(GTK_STEXT(compose->text),
621 NULL, NULL, NULL, "\n", 1);
625 Compose * compose_generic_new(PrefsAccount *account, const gchar *to, FolderItem *item)
629 if (item && item->prefs && item->prefs->enable_default_account)
630 account = account_find_from_id(item->prefs->default_account);
632 if (!account) account = cur_account;
633 g_return_val_if_fail(account != NULL, NULL);
635 compose = compose_create(account, COMPOSE_NEW);
636 compose->replyinfo = NULL;
638 if (prefs_common.auto_sig)
639 compose_insert_sig(compose);
640 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
641 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
643 if (account->protocol != A_NNTP) {
645 set_compose_entries(compose, to);
647 } else if(item && item->prefs->enable_default_to) {
648 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
650 if (item && item->ret_rcpt) {
651 GtkItemFactory *ifactory;
653 ifactory = gtk_item_factory_from_widget(compose->menubar);
654 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
658 compose_entry_append(compose, to, COMPOSE_NEWSGROUPS);
661 gtk_widget_grab_focus(compose->subject_entry);
663 if (prefs_common.auto_exteditor)
664 compose_exec_ext_editor(compose);
669 #define CHANGE_FLAGS(msginfo) \
671 if (msginfo->folder->folder->change_flags != NULL) \
672 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
678 Compose * compose_new_followup_and_replyto(PrefsAccount *account,
679 const gchar *followupto, gchar * to)
683 if (!account) account = cur_account;
684 g_return_val_if_fail(account != NULL, NULL);
685 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
687 compose = compose_create(account, COMPOSE_NEW);
689 if (prefs_common.auto_sig)
690 compose_insert_sig(compose);
691 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
692 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
694 compose_entry_append(compose, to, COMPOSE_TO);
695 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
696 gtk_widget_grab_focus(compose->subject_entry);
702 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
703 gboolean ignore_replyto)
705 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE);
708 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
710 gboolean ignore_replyto)
712 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE);
715 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
717 gboolean ignore_replyto,
718 gboolean followup_and_reply_to)
721 PrefsAccount *account;
722 PrefsAccount *reply_account;
725 g_return_if_fail(msginfo != NULL);
726 g_return_if_fail(msginfo->folder != NULL);
729 /* select the account set in folderitem's property (if enabled) */
730 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
731 account = account_find_from_id(msginfo->folder->prefs->default_account);
733 /* select the account for the whole folder (IMAP / NNTP) */
735 account = msginfo->folder->folder->account;
737 /* select account by to: and cc: header if enabled */
738 if (prefs_common.reply_account_autosel) {
739 if (!account && msginfo->to) {
741 Xstrdup_a(to, msginfo->to, return);
743 account = account_find_from_address(to);
747 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
749 account = account_find_from_address(cc);
754 /* select current account */
755 if (!account) account = cur_account;
756 g_return_if_fail(account != NULL);
758 if (ignore_replyto && account->protocol == A_NNTP &&
759 !followup_and_reply_to) {
761 account_find_from_address(account->address);
763 reply_account = compose_current_mail_account();
767 reply_account = account;
769 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
770 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
772 CHANGE_FLAGS(msginfo);
774 compose = compose_create(account, COMPOSE_REPLY);
775 compose->replyinfo = procmsg_msginfo_copy(msginfo);
777 #if 0 /* NEW COMPOSE GUI */
778 if (followup_and_reply_to) {
779 gtk_widget_show(compose->to_hbox);
780 gtk_widget_show(compose->to_entry);
781 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
782 compose->use_to = TRUE;
785 if (msginfo->folder && msginfo->folder->ret_rcpt) {
786 GtkItemFactory *ifactory;
788 ifactory = gtk_item_factory_from_widget(compose->menubar);
789 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
792 if (compose_parse_header(compose, msginfo) < 0) return;
793 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
794 followup_and_reply_to);
796 text = GTK_STEXT(compose->text);
797 gtk_stext_freeze(text);
803 if (prefs_common.quotemark && *prefs_common.quotemark)
804 qmark = prefs_common.quotemark;
808 quote_str = compose_quote_fmt(compose, msginfo,
809 prefs_common.quotefmt,
813 if (prefs_common.auto_sig)
814 compose_insert_sig(compose);
815 gtk_editable_set_position(GTK_EDITABLE(text), 0);
816 gtk_stext_set_point(text, 0);
818 if (quote && prefs_common.linewrap_quote) {
819 compose_wrap_line_all(compose);
822 gtk_stext_thaw(text);
823 gtk_widget_grab_focus(compose->text);
825 if (prefs_common.auto_exteditor)
826 compose_exec_ext_editor(compose);
830 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
835 g_return_val_if_fail(mimeinfo != NULL, NULL);
837 base = mimeinfo->filename ? mimeinfo->filename
838 : mimeinfo->name ? mimeinfo->name : NULL;
840 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
841 filename = g_strdup_printf("%s%smimetmp%i.html",
848 base = base ? base : "";
849 base = g_basename(base);
851 filename = g_strdup_printf("%s%smimetmp%i",
859 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
865 static gchar * mime_extract_file(gchar * source, MimeInfo *partinfo)
869 if (!partinfo) return;
871 filename = procmime_get_file_name(partinfo);
873 if (procmime_get_part(filename, source, partinfo) < 0)
875 (_("Can't get the part of multipart message."));
880 static void compose_attach_parts(Compose * compose,
890 gint boundary_len = 0;
892 glong fpos, prev_fpos;
897 g_return_if_fail(msginfo != NULL);
901 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
902 mimeinfo = procmime_scan_mime_header(fp);
903 if (!mimeinfo) break;
905 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
906 rfc2015_is_encrypted(mimeinfo)) {
907 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED);
909 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
910 !msginfo->plaintext_file &&
911 !msginfo->decryption_failed) {
912 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
913 if (msginfo->plaintext_file &&
914 !msginfo->decryption_failed) {
922 #else /* !USE_GPGME */
923 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
924 mimeinfo = procmime_scan_mime_header(fp);
925 #endif /* USE_GPGME */
928 if (!mimeinfo) return;
929 if (mimeinfo->mime_type == MIME_TEXT)
932 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
934 g_return_if_fail(mimeinfo != NULL);
935 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
937 if (mimeinfo->mime_type == MIME_MULTIPART) {
938 g_return_if_fail(mimeinfo->boundary != NULL);
939 g_return_if_fail(mimeinfo->sub == NULL);
941 g_return_if_fail(fp != NULL);
943 boundary = mimeinfo->boundary;
946 boundary_len = strlen(boundary);
948 /* look for first boundary */
949 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
950 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
957 if ((fpos = ftell(fp)) < 0) {
963 for (npart = 0;; npart++) {
965 gboolean eom = FALSE;
969 partinfo = procmime_scan_mime_header(fp);
970 if (!partinfo) break;
973 procmime_mimeinfo_insert(mimeinfo, partinfo);
975 procmime_mimeinfo_free(partinfo);
977 /* look for next boundary */
979 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
980 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
981 if (buf[2 + boundary_len] == '-' &&
982 buf[2 + boundary_len + 1] == '-')
988 eom = TRUE; /* broken MIME message */
991 partinfo->size = fpos - prev_fpos - strlen(buf);
996 source = procmsg_get_message_file_path(msginfo);
998 g_return_if_fail(mimeinfo != NULL);
1000 if (!mimeinfo->main && mimeinfo->parent)
1002 filename = mime_extract_file(source, mimeinfo);
1004 compose_attach_append_with_type(compose, filename,
1005 mimeinfo->content_type,
1006 mimeinfo->mime_type);
1011 if (mimeinfo->sub && mimeinfo->sub->children)
1013 filename = mime_extract_file(source, mimeinfo->sub);
1015 compose_attach_append_with_type(compose, filename,
1016 mimeinfo->content_type,
1017 mimeinfo->sub->mime_type);
1022 if (mimeinfo->children) {
1025 child = mimeinfo->children;
1027 filename = mime_extract_file(source, child);
1029 compose_attach_append_with_type(compose, filename,
1030 child->content_type,
1035 child = child->next;
1041 procmime_mimeinfo_free_all(mimeinfo);
1045 #define INSERT_FW_HEADER(var, hdr) \
1046 if (msginfo->var && *msginfo->var) { \
1047 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1048 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1049 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1052 Compose *compose_forward(PrefsAccount * account, MsgInfo *msginfo,
1056 /* PrefsAccount *account; */
1059 g_return_val_if_fail(msginfo != NULL, NULL);
1060 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1062 account = msginfo->folder->folder->account;
1063 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1065 Xstrdup_a(to, msginfo->to, return);
1066 extract_address(to);
1067 account = account_find_from_address(to);
1070 if(!account && prefs_common.forward_account_autosel) {
1072 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1073 extract_address(cc);
1074 account = account_find_from_address(cc);
1078 if (account == NULL) {
1079 account = cur_account;
1081 account = msginfo->folder->folder->account;
1082 if (!account) account = cur_account;
1085 g_return_val_if_fail(account != NULL, NULL);
1087 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1088 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1089 CHANGE_FLAGS(msginfo);
1091 compose = compose_create(account, COMPOSE_FORWARD);
1093 if (msginfo->subject && *msginfo->subject) {
1094 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1095 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1099 text = GTK_STEXT(compose->text);
1100 gtk_stext_freeze(text);
1105 msgfile = procmsg_get_message_file_path(msginfo);
1106 if (!is_file_exist(msgfile))
1107 g_warning(_("%s: file not exist\n"), msgfile);
1109 compose_attach_append(compose, msgfile,
1110 MIME_MESSAGE_RFC822);
1117 if (prefs_common.fw_quotemark && *prefs_common.fw_quotemark)
1118 qmark = prefs_common.fw_quotemark;
1122 quote_str = compose_quote_fmt(compose, msginfo,
1123 prefs_common.fw_quotefmt, qmark);
1124 compose_attach_parts(compose, msginfo);
1127 if (prefs_common.auto_sig)
1128 compose_insert_sig(compose);
1129 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1130 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1132 gtk_stext_thaw(text);
1133 #if 0 /* NEW COMPOSE GUI */
1134 if (account->protocol != A_NNTP)
1135 gtk_widget_grab_focus(compose->to_entry);
1137 gtk_widget_grab_focus(compose->newsgroups_entry);
1139 gtk_widget_grab_focus(compose->header_last->entry);
1141 if (prefs_common.auto_exteditor)
1142 compose_exec_ext_editor(compose);
1147 #undef INSERT_FW_HEADER
1149 Compose * compose_forward_multiple(PrefsAccount * account,
1150 GSList *msginfo_list)
1157 g_return_val_if_fail(msginfo_list != NULL, NULL);
1159 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1160 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1164 if (account == NULL) {
1165 account = cur_account;
1167 account = msginfo->folder->folder->account;
1168 if (!account) account = cur_account;
1171 g_return_val_if_fail(account != NULL, NULL);
1173 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1174 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1175 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1176 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1179 compose = compose_create(account, COMPOSE_FORWARD);
1181 text = GTK_STEXT(compose->text);
1182 gtk_stext_freeze(text);
1184 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1185 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1186 if (!is_file_exist(msgfile))
1187 g_warning(_("%s: file not exist\n"), msgfile);
1189 compose_attach_append(compose, msgfile,
1190 MIME_MESSAGE_RFC822);
1194 if (prefs_common.auto_sig)
1195 compose_insert_sig(compose);
1196 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1197 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1199 gtk_stext_thaw(text);
1200 #if 0 /* NEW COMPOSE GUI */
1201 if (account->protocol != A_NNTP)
1202 gtk_widget_grab_focus(compose->to_entry);
1204 gtk_widget_grab_focus(compose->newsgroups_entry);
1210 void compose_reedit(MsgInfo *msginfo)
1213 PrefsAccount *account;
1216 gchar buf[BUFFSIZE];
1218 g_return_if_fail(msginfo != NULL);
1219 g_return_if_fail(msginfo->folder != NULL);
1221 account = msginfo->folder->folder->account;
1223 if(!account&& prefs_common.reedit_account_autosel) {
1224 gchar from[BUFFSIZE];
1225 if(!get_header_from_msginfo(msginfo,from,sizeof(from),"FROM:")){ /* Found a FROM header */
1226 extract_address(from);
1227 account = account_find_from_address(from);
1230 if (!account) account = cur_account;
1231 g_return_if_fail(account != NULL);
1233 compose = compose_create(account, COMPOSE_REEDIT);
1234 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1236 if (compose_parse_header(compose, msginfo) < 0) return;
1237 compose_reedit_set_entry(compose, msginfo);
1239 text = GTK_STEXT(compose->text);
1240 gtk_stext_freeze(text);
1242 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1243 g_warning(_("Can't get text part\n"));
1245 while (fgets(buf, sizeof(buf), fp) != NULL)
1246 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1249 compose_attach_parts(compose, msginfo);
1251 gtk_stext_thaw(text);
1252 gtk_widget_grab_focus(compose->text);
1254 if (prefs_common.auto_exteditor)
1255 compose_exec_ext_editor(compose);
1258 GList *compose_get_compose_list(void)
1260 return compose_list;
1263 void compose_entry_append(Compose *compose, const gchar *address,
1264 ComposeEntryType type)
1270 if (!address || *address == '\0') return;
1272 #if 0 /* NEW COMPOSE GUI */
1275 entry = GTK_ENTRY(compose->cc_entry);
1278 entry = GTK_ENTRY(compose->bcc_entry);
1280 case COMPOSE_NEWSGROUPS:
1281 entry = GTK_ENTRY(compose->newsgroups_entry);
1285 entry = GTK_ENTRY(compose->to_entry);
1289 text = gtk_entry_get_text(entry);
1291 gtk_entry_append_text(entry, ", ");
1292 gtk_entry_append_text(entry, address);
1300 header = N_("Bcc:");
1302 case COMPOSE_REPLYTO:
1303 header = N_("Reply-To:");
1305 case COMPOSE_NEWSGROUPS:
1306 header = N_("Newsgroups:");
1308 case COMPOSE_FOLLOWUPTO:
1309 header = N_( "Followup-To:");
1316 header = prefs_common.trans_hdr ? gettext(header) : header;
1318 compose_add_header_entry(compose, header, (gchar *)address);
1321 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1323 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1324 {"Cc:", NULL, FALSE},
1325 {"References:", NULL, FALSE},
1326 {"Bcc:", NULL, FALSE},
1327 {"Newsgroups:", NULL, FALSE},
1328 {"Followup-To:", NULL, FALSE},
1329 {"X-Mailing-List:", NULL, FALSE},
1330 {"X-BeenThere:", NULL, FALSE},
1331 {NULL, NULL, FALSE}};
1341 H_X_MAILING_LIST = 6,
1347 g_return_val_if_fail(msginfo != NULL, -1);
1349 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1350 procheader_get_header_fields(fp, hentry);
1353 if (hentry[H_REPLY_TO].body != NULL) {
1354 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1355 compose->replyto = hentry[H_REPLY_TO].body;
1356 hentry[H_REPLY_TO].body = NULL;
1358 if (hentry[H_CC].body != NULL) {
1359 conv_unmime_header_overwrite(hentry[H_CC].body);
1360 compose->cc = hentry[H_CC].body;
1361 hentry[H_CC].body = NULL;
1363 if (hentry[H_X_MAILING_LIST].body != NULL) {
1364 /* this is good enough to parse debian-devel */
1365 char * buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1366 g_return_val_if_fail(buf != NULL, -1 );
1367 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1368 compose->mailinglist = g_strdup(buf);
1370 g_free(hentry[H_X_MAILING_LIST].body);
1371 hentry[H_X_MAILING_LIST].body = NULL ;
1373 if (hentry[H_X_BEENTHERE].body != NULL) {
1374 /* this is good enough to parse the sylpheed-claws lists */
1375 char * buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1376 g_return_val_if_fail(buf != NULL, -1 );
1377 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1378 compose->mailinglist = g_strdup(buf);
1380 g_free(hentry[H_X_BEENTHERE].body);
1381 hentry[H_X_BEENTHERE].body = NULL ;
1383 if (hentry[H_REFERENCES].body != NULL) {
1384 if (compose->mode == COMPOSE_REEDIT)
1385 compose->references = hentry[H_REFERENCES].body;
1387 compose->references = compose_parse_references
1388 (hentry[H_REFERENCES].body, msginfo->msgid);
1389 g_free(hentry[H_REFERENCES].body);
1391 hentry[H_REFERENCES].body = NULL;
1393 if (hentry[H_BCC].body != NULL) {
1394 if (compose->mode == COMPOSE_REEDIT) {
1395 conv_unmime_header_overwrite(hentry[H_BCC].body);
1396 compose->bcc = hentry[H_BCC].body;
1398 g_free(hentry[H_BCC].body);
1399 hentry[H_BCC].body = NULL;
1401 if (hentry[H_NEWSGROUPS].body != NULL) {
1402 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1403 hentry[H_NEWSGROUPS].body = NULL;
1405 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1406 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1407 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1408 hentry[H_FOLLOWUP_TO].body = NULL;
1411 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1412 compose->inreplyto = g_strdup(msginfo->inreplyto);
1413 else if (compose->mode != COMPOSE_REEDIT &&
1414 msginfo->msgid && *msginfo->msgid) {
1415 compose->inreplyto = g_strdup(msginfo->msgid);
1417 if (!compose->references) {
1418 if (msginfo->inreplyto && *msginfo->inreplyto)
1419 compose->references =
1420 g_strdup_printf("<%s>\n\t<%s>",
1424 compose->references =
1425 g_strconcat("<", msginfo->msgid, ">",
1433 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1435 GSList *ref_id_list, *cur;
1439 ref_id_list = references_list_append(NULL, ref);
1440 if (!ref_id_list) return NULL;
1441 if (msgid && *msgid)
1442 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1447 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1448 /* "<" + Message-ID + ">" + CR+LF+TAB */
1449 len += strlen((gchar *)cur->data) + 5;
1451 if (len > MAX_REFERENCES_LEN) {
1452 /* remove second message-ID */
1453 if (ref_id_list && ref_id_list->next &&
1454 ref_id_list->next->next) {
1455 g_free(ref_id_list->next->data);
1456 ref_id_list = g_slist_remove
1457 (ref_id_list, ref_id_list->next->data);
1459 slist_free_strings(ref_id_list);
1460 g_slist_free(ref_id_list);
1467 new_ref = g_string_new("");
1468 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1469 if (new_ref->len > 0)
1470 g_string_append(new_ref, "\n\t");
1471 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1474 slist_free_strings(ref_id_list);
1475 g_slist_free(ref_id_list);
1477 new_ref_str = new_ref->str;
1478 g_string_free(new_ref, FALSE);
1483 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1484 const gchar *fmt, const gchar *qmark)
1486 GtkSText *text = GTK_STEXT(compose->text);
1487 gchar *quote_str = NULL;
1492 if (qmark != NULL) {
1493 quote_fmt_init(msginfo, NULL);
1494 quote_fmt_scan_string(qmark);
1497 buf = quote_fmt_get_buffer();
1499 alertpanel_error(_("Quote mark format error."));
1501 Xstrdup_a(quote_str, buf, return NULL)
1504 quote_fmt_init(msginfo, quote_str);
1505 quote_fmt_scan_string(fmt);
1508 buf = quote_fmt_get_buffer();
1510 alertpanel_error(_("Message reply/forward format error."));
1514 gtk_stext_freeze(text);
1515 gtk_stext_set_point(text, 0);
1516 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
1518 for (p = buf; *p != '\0'; ) {
1519 lastp = strchr(p, '\n');
1520 len = lastp ? lastp - p + 1 : -1;
1521 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1528 gtk_stext_thaw(text);
1533 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1534 gboolean to_all, gboolean ignore_replyto,
1535 gboolean followup_and_reply_to)
1540 GHashTable *to_table;
1542 g_return_if_fail(compose->account != NULL);
1543 g_return_if_fail(msginfo != NULL);
1545 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1546 compose_entry_append(compose,
1547 ((compose->mailinglist && !ignore_replyto)
1548 ? compose->mailinglist
1549 : (compose->replyto && !ignore_replyto)
1551 : msginfo->from ? msginfo->from : ""),
1553 if (compose->account->protocol == A_NNTP)
1555 compose_entry_append(compose,
1556 msginfo->from ? msginfo->from : "",
1559 compose_entry_append(compose,
1560 compose->followup_to ? compose->followup_to
1561 : compose->newsgroups ? compose->newsgroups
1563 COMPOSE_NEWSGROUPS);
1565 compose_entry_append(compose,
1566 compose->followup_to ? compose->followup_to
1567 : compose->newsgroups ? compose->newsgroups
1569 COMPOSE_NEWSGROUPS);
1572 if (msginfo->subject && *msginfo->subject) {
1573 gchar *buf, *buf2, *p;
1575 buf = g_strdup(msginfo->subject);
1576 while (!strncasecmp(buf, "Re:", 3)) {
1578 while (isspace(*p)) p++;
1579 memmove(buf, p, strlen(p) + 1);
1582 buf2 = g_strdup_printf("Re: %s", buf);
1583 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1587 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1589 if (!to_all || compose->account->protocol == A_NNTP) return;
1591 from = g_strdup(compose->replyto ? compose->replyto :
1592 msginfo->from ? msginfo->from : "");
1593 extract_address(from);
1595 cc_list = address_list_append(NULL, msginfo->to);
1596 cc_list = address_list_append(cc_list, compose->cc);
1598 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1599 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1600 if (compose->account)
1601 g_hash_table_insert(to_table, compose->account->address,
1602 GINT_TO_POINTER(1));
1604 /* remove address on To: and that of current account */
1605 for (cur = cc_list; cur != NULL; ) {
1606 GSList *next = cur->next;
1608 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1609 cc_list = g_slist_remove(cc_list, cur->data);
1611 g_hash_table_insert(to_table, cur->data, cur);
1615 g_hash_table_destroy(to_table);
1619 for (cur = cc_list; cur != NULL; cur = cur->next)
1620 compose_entry_append(compose, (gchar *)cur->data,
1622 slist_free_strings(cc_list);
1623 g_slist_free(cc_list);
1627 #define SET_ENTRY(entry, str) \
1630 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1633 #define SET_ADDRESS(type, str) \
1636 compose_entry_append(compose, str, type); \
1639 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1641 g_return_if_fail(msginfo != NULL);
1643 SET_ENTRY(subject_entry, msginfo->subject);
1644 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1645 SET_ADDRESS(COMPOSE_CC, compose->cc);
1646 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1647 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1649 #if 0 /* NEW COMPOSE GUI */
1651 GtkItemFactory *ifactory;
1652 GtkWidget *menuitem;
1654 ifactory = gtk_item_factory_from_widget(compose->menubar);
1655 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1656 gtk_check_menu_item_set_active
1657 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1659 if (compose->replyto) {
1660 GtkItemFactory *ifactory;
1661 GtkWidget *menuitem;
1663 ifactory = gtk_item_factory_from_widget(compose->menubar);
1664 menuitem = gtk_item_factory_get_item
1665 (ifactory, "/Message/Reply to");
1666 gtk_check_menu_item_set_active
1667 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1675 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1682 size_t buf_len = 128;
1684 if (strlen(sigfile) < 2)
1687 sigprg = popen(sigfile+1, "r");
1690 buf = g_malloc(buf_len);
1693 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1694 "Unable to insert signature (malloc failed)\n", -1);
1700 while (!feof(sigprg)) {
1701 bzero(buf, buf_len);
1702 fread(buf, buf_len-1, 1, sigprg);
1703 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1711 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1712 "Can't exec file: ", -1);
1713 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1718 static void compose_insert_sig(Compose *compose)
1722 if (compose->account && compose->account->sig_path)
1723 sigfile = g_strdup(compose->account->sig_path);
1725 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1726 DEFAULT_SIGNATURE, NULL);
1729 if (!is_file_or_fifo_exist(sigfile) & (sigfile[0] != '|')) {
1734 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1735 if (prefs_common.sig_sep) {
1736 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1737 prefs_common.sig_sep, -1);
1738 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1742 if (sigfile[0] == '|')
1744 compose_exec_sig(compose, sigfile);
1748 compose_insert_file(compose, sigfile);
1753 static void compose_insert_file(Compose *compose, const gchar *file)
1755 GtkSText *text = GTK_STEXT(compose->text);
1756 gchar buf[BUFFSIZE];
1760 g_return_if_fail(file != NULL);
1762 if ((fp = fopen(file, "r")) == NULL) {
1763 FILE_OP_ERROR(file, "fopen");
1767 gtk_stext_freeze(text);
1769 while (fgets(buf, sizeof(buf), fp) != NULL) {
1770 /* Strip <CR> if DOS/Windoze file, replace <CR> with <LF> if MAC file */
1772 if (len > 1 && buf[len - 2] == '\r' && buf[len - 1] == '\n') {
1773 buf[len - 2] = '\n';
1774 buf[len - 1] = '\0';
1777 if (buf[len] == '\r')
1781 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1784 gtk_stext_thaw(text);
1789 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
1790 ContentType cnttype)
1792 gchar *text[N_ATTACH_COLS];
1795 text[COL_MIMETYPE] = ainfo->content_type;
1796 text[COL_SIZE] = to_human_readable(ainfo->size);
1797 text[COL_NAME] = ainfo->name;
1799 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1800 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1802 if (cnttype != MIME_MESSAGE_RFC822)
1803 compose_changed_cb(NULL, compose);
1806 static void compose_attach_append_with_type(Compose *compose,
1809 ContentType cnttype)
1814 if (!is_file_exist(file)) {
1815 g_warning(_("File %s doesn't exist\n"), file);
1818 if ((size = get_file_size(file)) < 0) {
1819 g_warning(_("Can't get file size of %s\n"), file);
1823 alertpanel_notice(_("File %s is empty\n"), file);
1826 #if 0 /* NEW COMPOSE GUI */
1827 if (!compose->use_attach) {
1828 GtkItemFactory *ifactory;
1829 GtkWidget *menuitem;
1831 ifactory = gtk_item_factory_from_widget(compose->menubar);
1832 menuitem = gtk_item_factory_get_item(ifactory,
1834 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1838 ainfo = g_new0(AttachInfo, 1);
1839 ainfo->file = g_strdup(file);
1841 if (cnttype == MIME_MESSAGE_RFC822) {
1842 ainfo->encoding = ENC_7BIT;
1843 ainfo->name = g_strdup_printf(_("Message: %s"),
1846 ainfo->encoding = ENC_BASE64;
1847 ainfo->name = g_strdup(g_basename(file));
1850 ainfo->content_type = g_strdup(type);
1853 compose_attach_info(compose, ainfo, cnttype);
1856 static void compose_attach_append(Compose *compose, const gchar *file,
1857 ContentType cnttype)
1860 gchar *text[N_ATTACH_COLS];
1864 if (!is_file_exist(file)) {
1865 g_warning(_("File %s doesn't exist\n"), file);
1868 if ((size = get_file_size(file)) < 0) {
1869 g_warning(_("Can't get file size of %s\n"), file);
1873 alertpanel_notice(_("File %s is empty\n"), file);
1876 #if 0 /* NEW COMPOSE GUI */
1877 if (!compose->use_attach) {
1878 GtkItemFactory *ifactory;
1879 GtkWidget *menuitem;
1881 ifactory = gtk_item_factory_from_widget(compose->menubar);
1882 menuitem = gtk_item_factory_get_item(ifactory,
1884 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1888 ainfo = g_new0(AttachInfo, 1);
1889 ainfo->file = g_strdup(file);
1891 if (cnttype == MIME_MESSAGE_RFC822) {
1892 ainfo->content_type = g_strdup("message/rfc822");
1893 ainfo->encoding = ENC_7BIT;
1894 ainfo->name = g_strdup_printf(_("Message: %s"),
1897 ainfo->content_type = procmime_get_mime_type(file);
1898 if (!ainfo->content_type)
1899 ainfo->content_type =
1900 g_strdup("application/octet-stream");
1901 ainfo->encoding = ENC_BASE64;
1902 ainfo->name = g_strdup(g_basename(file));
1906 compose_attach_info(compose, ainfo, cnttype);
1909 static void compose_wrap_line(Compose *compose)
1911 GtkSText *text = GTK_STEXT(compose->text);
1912 gint ch_len, last_ch_len;
1913 gchar cbuf[MB_LEN_MAX], last_ch;
1917 gint p_start, p_end;
1918 gint line_pos, cur_pos;
1919 gint line_len, cur_len;
1921 #define GET_STEXT(pos) \
1922 if (text->use_wchar) \
1923 ch_len = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
1925 cbuf[0] = GTK_STEXT_INDEX(text, (pos)); \
1929 gtk_stext_freeze(text);
1931 text_len = gtk_stext_get_length(text);
1933 /* check to see if the point is on the paragraph mark (empty line). */
1934 cur_pos = gtk_stext_get_point(text);
1936 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
1938 goto compose_end; /* on the paragraph mark */
1939 GET_STEXT(cur_pos - 1);
1940 if (ch_len == 1 && *cbuf == '\n')
1941 goto compose_end; /* on the paragraph mark */
1944 /* find paragraph start. */
1945 line_end = quoted = 0;
1946 for (p_start = cur_pos; p_start >= 0; --p_start) {
1948 if (ch_len == 1 && *cbuf == '\n') {
1950 goto compose_end; /* quoted part */
1957 if (ch_len == 1 && strchr(">:#", *cbuf))
1959 else if (ch_len != 1 || !isspace(*cbuf))
1968 /* find paragraph end. */
1970 for (p_end = cur_pos; p_end < text_len; p_end++) {
1972 if (ch_len == 1 && *cbuf == '\n') {
1979 if (line_end && ch_len == 1 && strchr(">:#", *cbuf))
1980 goto compose_end; /* quoted part */
1985 if (p_end >= text_len)
1988 if (p_start >= p_end)
1991 line_len = cur_len = 0;
1995 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2005 if (ch_len == 1 && isspace(*cbuf))
2008 if (ch_len == 1 && *cbuf == '\n') {
2010 if (last_ch_len == 1 && !isspace(last_ch)) {
2011 if (cur_pos + 1 < p_end) {
2012 GET_STEXT(cur_pos + 1);
2013 if (ch_len == 1 && !isspace(*cbuf))
2017 gtk_stext_set_point(text, cur_pos + 1);
2018 gtk_stext_backward_delete(text, 1);
2020 gtk_stext_set_point(text, cur_pos);
2021 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2031 last_ch_len = ch_len;
2035 line_pos = cur_pos + 1;
2036 line_len = cur_len + ch_len;
2039 if (cur_len + ch_len > prefs_common.linewrap_len &&
2043 GET_STEXT(line_pos - 1);
2044 if (ch_len == 1 && isspace(*cbuf)) {
2045 gtk_stext_set_point(text, line_pos);
2046 gtk_stext_backward_delete(text, 1);
2055 gtk_stext_set_point(text, line_pos);
2056 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2060 cur_len = cur_len - line_len + ch_len;
2066 line_pos = cur_pos + 1;
2067 line_len = cur_len + ch_len;
2073 gtk_stext_thaw(text);
2078 /* return indent length */
2079 static guint get_indent_length(GtkSText *text, guint start_pos,
2081 gint indent_len = 0;
2083 gchar cbuf[MB_CUR_MAX];
2085 for (i = start_pos; i < text_len; i++) {
2086 if (text->use_wchar)
2088 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, i));
2090 cbuf[0] = GTK_STEXT_INDEX(text, i);
2095 /* allow space, tab, > or | */
2096 if (cbuf[0] != ' ' && cbuf[0] != '\t' &&
2097 cbuf[0] != '>' && cbuf[0] != '|')
2105 /* insert quotation string when line was wrapped, we know these
2106 are single byte characters */
2107 static guint ins_quote(GtkSText *text, guint quote_len, guint indent_len,
2108 guint prev_line_pos, guint text_len,
2114 for (i = 0; i < indent_len; i++) {
2115 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2116 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2118 ins_len = indent_len;
2121 gtk_stext_insert(text, NULL, NULL, NULL, quote_fmt, quote_len);
2122 ins_len = quote_len;
2130 /* Darko: used when I debug wrapping */
2131 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2136 printf("%d [", pos);
2137 for (i = pos; i < tlen; i++)
2139 ch = GTK_STEXT_INDEX(text, i);
2140 if (breakoncr && ch == '\n')
2148 static void compose_wrap_line_all(Compose *compose)
2150 GtkSText *text = GTK_STEXT(compose->text);
2152 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2153 gint line_len = 0, cur_len = 0;
2155 gint is_new_line = 1, do_delete = 0;
2156 guint qlen = 0, i_len = 0;
2157 guint linewrap_quote = prefs_common.linewrap_quote;
2158 guint linewrap_len = prefs_common.linewrap_len;
2159 gchar *qfmt = prefs_common.quotemark;
2160 gchar cbuf[MB_LEN_MAX];
2162 gtk_stext_freeze(text);
2164 /* make text buffer contiguous */
2165 gtk_stext_compact_buffer(text);
2167 tlen = gtk_stext_get_length(text);
2169 for (; cur_pos < tlen; cur_pos++) {
2170 /* mark position of new line - needed for quotation wrap */
2171 if (linewrap_quote && is_new_line) {
2172 qlen = gtkstext_str_strcmp(text, cur_pos, tlen, qfmt);
2175 i_len = get_indent_length(text, cur_pos, tlen);
2181 printf("new line i_len=%d qlen=%d p_pos=", i_len, qlen);
2182 dump_text(text, p_pos, tlen, 1);
2186 /* get character(s) at current position */
2187 if (text->use_wchar)
2189 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
2191 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
2195 /* fix line length for tabs */
2196 if (ch_len == 1 && *cbuf == '\t') {
2197 guint tab_width = text->default_tab_width;
2198 guint tab_offset = line_len % tab_width;
2201 printf("found tab at pos=%d line_len=%d ", cur_pos,
2205 line_len += tab_width - tab_offset - 1;
2209 printf("new_len=%d\n", line_len);
2213 /* we have encountered line break */
2214 if (ch_len == 1 && *cbuf == '\n') {
2217 gchar cb[MB_CUR_MAX];
2220 printf("found CR at %d\n", cur_pos);
2222 /* if it's just quotation + newline skip it */
2223 if (i_len && (cur_pos + 1 < tlen)) {
2224 /* check if text at new line matches indent */
2225 ilen = gtkstext_strncmp(text, cur_pos + 1,
2226 p_pos, i_len, tlen);
2227 if (cur_pos + ilen < tlen) {
2228 if (text->use_wchar)
2229 clen = wctomb(cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos + ilen + 1));
2231 cb[0] = GTK_STEXT_INDEX(text,
2232 cur_pos + ilen + 1);
2235 /* no need to join the lines */
2236 if ((clen == 1) && (cb[0] == '\n'))
2242 printf("qlen=%d l_len=%d wrap_len=%d do_del=%d\n",
2243 qlen, line_len, linewrap_len, do_delete);
2245 /* should we delete to perform smart wrapping */
2246 if (qlen && line_len < linewrap_len && do_delete) {
2247 /* get rid of newline */
2248 gtk_stext_set_point(text, cur_pos);
2249 gtk_stext_forward_delete(text, 1);
2252 /* if text starts with quote fmt or with
2253 indent string, delete them */
2255 ilen = gtkstext_strncmp(text, cur_pos,
2259 gtk_stext_forward_delete(text,
2265 if (gtkstext_str_strcmp(text, cur_pos,
2267 gtk_stext_forward_delete(text,
2273 if (text->use_wchar)
2275 (cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
2277 cb[0] = GTK_STEXT_INDEX(text, cur_pos);
2281 /* insert space if it's alphanumeric */
2282 if ((cur_pos != line_pos) &&
2283 ((clen > 1) || isalnum(cb[0]))) {
2284 gtk_stext_insert(text, NULL, NULL,
2286 gtk_stext_compact_buffer(text);
2290 /* and start over with current line */
2291 cur_pos = p_pos - 1;
2293 line_len = cur_len = 0;
2298 printf("after delete l_pos=");
2299 dump_text(text, line_pos, tlen, 1);
2304 /* mark new line beginning */
2305 line_pos = cur_pos + 1;
2306 line_len = cur_len = 0;
2318 /* possible line break */
2319 if (ch_len == 1 && isspace(*cbuf)) {
2320 line_pos = cur_pos + 1;
2321 line_len = cur_len + ch_len;
2324 /* are we over wrapping length set in preferences ? */
2325 if (cur_len + ch_len > linewrap_len) {
2329 printf("should wrap cur_pos=%d ", cur_pos);
2330 dump_text(text, p_pos, tlen, 1);
2331 dump_text(text, line_pos, tlen, 1);
2333 /* force wrapping if it is one long word but not URL */
2334 if (p_pos + i_len == line_pos)
2335 if (!is_url_string(text, line_pos, tlen))
2336 line_pos = cur_pos - 1;
2338 printf("new line_pos=%d\n", line_pos);
2341 /* if next character is space delete it */
2342 if (text->use_wchar)
2343 clen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
2345 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
2348 if (clen == 1 && isspace(*cbuf)) {
2349 if (p_pos + i_len != line_pos ||
2350 !is_url_string(text, line_pos, tlen)) {
2351 gtk_stext_set_point(text, line_pos);
2352 gtk_stext_backward_delete(text, 1);
2361 /* if it is URL at beginning of line don't wrap */
2362 if (p_pos + i_len == line_pos &&
2363 is_url_string(text, line_pos, tlen)) {
2365 printf("found URL at ");
2366 dump_text(text, line_pos, tlen, 1);
2372 gtk_stext_set_point(text, line_pos);
2373 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2374 gtk_stext_compact_buffer(text);
2378 cur_len = cur_len - line_len + ch_len;
2381 printf("after CR insert ");
2382 dump_text(text, line_pos, tlen, 1);
2385 /* should we insert quotation ? */
2386 if (linewrap_quote && qlen) {
2387 /* only if line is not already quoted */
2388 if (!gtkstext_str_strcmp(text, line_pos,
2392 if (line_pos - p_pos > i_len) {
2393 ins_len = ins_quote(text,
2400 gtk_stext_compact_buffer(text);
2404 /* for loop will increase it */
2405 cur_pos = line_pos - 1;
2408 /* start over with current line */
2412 printf("after quote insert ");
2413 dump_text(text, line_pos, tlen, 1);
2421 line_pos = cur_pos + 1;
2422 line_len = cur_len + ch_len;
2424 /* advance to next character in buffer */
2428 gtk_stext_thaw(text);
2431 static void compose_set_title(Compose *compose)
2436 edited = compose->modified ? _(" [Edited]") : "";
2437 if (compose->account && compose->account->address)
2438 str = g_strdup_printf(_("%s - Compose message%s"),
2439 compose->account->address, edited);
2441 str = g_strdup_printf(_("Compose message%s"), edited);
2442 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2447 * compose_current_mail_account:
2449 * Find a current mail account (the currently selected account, or the
2450 * default account, if a news account is currently selected). If a
2451 * mail account cannot be found, display an error message.
2453 * Return value: Mail account, or NULL if not found.
2455 static PrefsAccount *
2456 compose_current_mail_account(void)
2460 if (cur_account && cur_account->protocol != A_NNTP)
2463 ac = account_get_default();
2464 if (!ac || ac->protocol == A_NNTP) {
2465 alertpanel_error(_("Account for sending mail is not specified.\n"
2466 "Please select a mail account before sending."));
2473 gboolean compose_check_for_valid_recipient(Compose *compose) {
2474 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2475 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2476 gboolean recipient_found = FALSE;
2480 /* free to and newsgroup list */
2481 slist_free_strings(compose->to_list);
2482 g_slist_free(compose->to_list);
2483 compose->to_list = NULL;
2485 slist_free_strings(compose->newsgroup_list);
2486 g_slist_free(compose->newsgroup_list);
2487 compose->newsgroup_list = NULL;
2489 /* search header entries for to and newsgroup entries */
2490 for(list = compose->header_list; list; list = list->next) {
2493 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((compose_headerentry *)list->data)->combo)->entry));
2494 entry = gtk_editable_get_chars(GTK_EDITABLE(((compose_headerentry *)list->data)->entry), 0, -1);
2496 if(entry[0] != '\0') {
2497 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2498 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2499 compose->to_list = address_list_append(compose->to_list, entry);
2500 recipient_found = TRUE;
2503 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2504 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2505 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2506 recipient_found = TRUE;
2512 return recipient_found;
2515 gint compose_send(Compose *compose)
2521 val = compose_queue(compose, &msgnum, &folder);
2523 alertpanel_error(_("Could not queue message for sending"));
2527 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2529 folder_item_remove_msg(folder, msgnum);
2530 folderview_update_item(folder, TRUE);
2536 #if 0 /* compose restructure */
2537 gint compose_send(Compose *compose)
2539 gchar tmp[MAXPATHLEN + 1];
2541 static gboolean lock = FALSE;
2545 g_return_val_if_fail(compose->account != NULL, -1);
2546 g_return_val_if_fail(compose->orig_account != NULL, -1);
2550 if(!compose_check_for_valid_recipient(compose)) {
2551 alertpanel_error(_("Recipient is not specified."));
2556 /* write to temporary file */
2557 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2558 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2560 if (prefs_common.linewrap_at_send)
2561 compose_wrap_line_all(compose);
2563 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2568 if (!compose->to_list && !compose->newsgroup_list) {
2569 g_warning(_("can't get recipient list."));
2575 if (compose->to_list) {
2578 #if 0 /* NEW COMPOSE GUI */
2579 if (compose->account->protocol != A_NNTP)
2580 ac = compose->account;
2581 else if (compose->orig_account->protocol != A_NNTP)
2582 ac = compose->orig_account;
2583 else if (cur_account && cur_account->protocol != A_NNTP)
2586 ac = compose_current_mail_account();
2594 ac = compose->account;
2596 ok = send_message(tmp, ac, compose->to_list);
2597 statusbar_pop_all();
2600 if (ok == 0 && compose->newsgroup_list) {
2603 if (compose->account->protocol == A_NNTP)
2604 folder = FOLDER(compose->account->folder);
2606 folder = FOLDER(compose->orig_account->folder);
2608 ok = news_post(folder, tmp);
2610 alertpanel_error(_("Error occurred while posting the message to %s ."),
2611 compose->account->nntp_server);
2618 /* queue message if failed to send */
2620 if (prefs_common.queue_msg) {
2625 _("Error occurred while sending the message.\n"
2626 "Put this message into queue folder?"),
2627 _("OK"), _("Cancel"), NULL);
2628 if (G_ALERTDEFAULT == val) {
2629 ok = compose_queue(compose, tmp);
2631 alertpanel_error(_("Can't queue the message."));
2634 alertpanel_error(_("Error occurred while sending the message."));
2636 if (compose->mode == COMPOSE_REEDIT) {
2637 compose_remove_reedit_target(compose);
2638 if (compose->targetinfo)
2639 folderview_update_item
2640 (compose->targetinfo->folder, TRUE);
2644 /* save message to outbox */
2645 if (ok == 0 && prefs_common.savemsg) {
2646 if (compose_save_to_outbox(compose, tmp) < 0)
2648 (_("Can't save the message to outbox."));
2657 static gboolean compose_use_attach(Compose *compose) {
2658 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2665 static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
2668 gchar buf[BUFFSIZE];
2670 gboolean first_address;
2672 compose_headerentry *headerentry;
2673 gchar * headerentryname;
2674 gchar * header_w_colon;
2678 debug_print(_("Writing bounce header\n"));
2680 header_w_colon = g_strconcat("To:", NULL);
2681 to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2682 header_w_colon = g_strconcat("Cc:", NULL);
2683 cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2685 first_address = TRUE;
2686 for(list = compose->header_list; list; list = list->next) {
2687 headerentry = ((compose_headerentry *)list->data);
2688 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2690 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2691 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2692 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2693 Xstrdup_a(str, str, return -1);
2695 if(str[0] != '\0') {
2696 compose_convert_header
2697 (buf, sizeof(buf), str,
2698 strlen("Resent-To") + 2);
2700 fprintf(fp, "Resent-To: ");
2701 first_address = FALSE;
2705 fprintf(fp, "%s", buf);
2709 // if(!first_address) {
2717 static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
2719 gchar buf[BUFFSIZE];
2721 /* struct utsname utsbuf; */
2723 g_return_val_if_fail(fp != NULL, -1);
2724 g_return_val_if_fail(compose->account != NULL, -1);
2725 g_return_val_if_fail(compose->account->address != NULL, -1);
2728 get_rfc822_date(buf, sizeof(buf));
2729 fprintf(fp, "Resent-Date: %s\n", buf);
2732 if (compose->account->name && *compose->account->name) {
2733 compose_convert_header
2734 (buf, sizeof(buf), compose->account->name,
2736 fprintf(fp, "Resent-From: %s <%s>\n",
2737 buf, compose->account->address);
2739 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2742 compose_bounce_write_headers_from_headerlist(compose, fp);
2744 /* separator between header and body */
2750 static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
2755 gchar buf[BUFFSIZE];
2757 if ((fp = fopen(compose->bounce_filename, "r")) == NULL) {
2758 FILE_OP_ERROR(file, "fopen");
2762 if ((fdest = fopen(file, "a+")) == NULL) {
2763 FILE_OP_ERROR(file, "fopen");
2768 /* chmod for security */
2769 if (change_file_mode_rw(fdest, file) < 0) {
2770 FILE_OP_ERROR(file, "chmod");
2771 g_warning(_("can't change file mode\n"));
2774 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2775 if (fputs(buf, fdest) == -1)
2777 if (fputs("\n", fdest) == -1)
2781 compose_bounce_write_headers(compose, fdest);
2783 while ((len = fread(buf, sizeof(gchar), BUFFSIZE, fp)) > 0) {
2784 if (fwrite(buf, sizeof(gchar), len, fdest) == -1)
2799 static gint compose_write_to_file(Compose *compose, const gchar *file,
2806 const gchar *out_codeset;
2807 EncodingType encoding;
2809 if ((fp = fopen(file, "a+")) == NULL) {
2810 FILE_OP_ERROR(file, "fopen");
2814 /* chmod for security */
2815 if (change_file_mode_rw(fp, file) < 0) {
2816 FILE_OP_ERROR(file, "chmod");
2817 g_warning(_("can't change file mode\n"));
2820 /* get all composed text */
2821 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2822 len = strlen(chars);
2823 if (is_ascii_str(chars)) {
2824 buf = g_strdup(chars);
2825 out_codeset = CS_US_ASCII;
2826 encoding = ENC_7BIT;
2828 const gchar *src_codeset;
2830 out_codeset = conv_get_outgoing_charset_str();
2831 if (!strcasecmp(out_codeset, CS_US_ASCII))
2832 out_codeset = CS_ISO_8859_1;
2833 encoding = procmime_get_encoding_for_charset(out_codeset);
2835 src_codeset = conv_get_current_charset_str();
2836 /* if current encoding is US-ASCII, set it the same as
2837 outgoing one to prevent code conversion failure */
2838 if (!strcasecmp(src_codeset, CS_US_ASCII))
2839 src_codeset = out_codeset;
2841 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
2842 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
2844 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
2849 alertpanel_error(_("Can't convert the codeset of the message."));
2856 if (compose_write_headers
2857 (compose, fp, out_codeset, encoding, is_draft) < 0) {
2858 g_warning(_("can't write headers\n"));
2865 if (compose_use_attach(compose)) {
2867 /* This prolog message is ignored by mime software and
2868 * because it would make our signing/encryption task
2869 * tougher, we don't emit it in that case */
2870 if (!compose->use_signing && !compose->use_encryption)
2872 fputs("This is a multi-part message in MIME format.\n", fp);
2874 fprintf(fp, "\n--%s\n", compose->boundary);
2875 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
2877 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2878 procmime_get_encoding_str(encoding));
2884 if (encoding == ENC_BASE64) {
2885 gchar outbuf[B64_BUFFSIZE];
2888 for (i = 0; i < len; i += B64_LINE_SIZE) {
2889 l = MIN(B64_LINE_SIZE, len - i);
2890 to64frombits(outbuf, buf + i, l);
2894 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
2895 FILE_OP_ERROR(file, "fwrite");
2903 if (compose_use_attach(compose))
2904 compose_write_attach(compose, fp);
2906 if (fclose(fp) == EOF) {
2907 FILE_OP_ERROR(file, "fclose");
2913 if (compose->use_signing) {
2914 if (rfc2015_sign(file, compose->account) < 0) {
2919 if (compose->use_encryption) {
2920 if (rfc2015_encrypt(file, compose->to_list) < 0) {
2925 #endif /* USE_GPGME */
2930 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
2936 if ((fp = fopen(file, "w")) == NULL) {
2937 FILE_OP_ERROR(file, "fopen");
2941 /* chmod for security */
2942 if (change_file_mode_rw(fp, file) < 0) {
2943 FILE_OP_ERROR(file, "chmod");
2944 g_warning(_("can't change file mode\n"));
2947 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2950 len = strlen(chars);
2951 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
2952 FILE_OP_ERROR(file, "fwrite");
2961 if (fclose(fp) == EOF) {
2962 FILE_OP_ERROR(file, "fclose");
2969 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
2976 debug_print(_("saving sent message...\n"));
2978 outbox = folder_get_default_outbox();
2979 path = folder_item_get_path(outbox);
2980 if (!is_dir_exist(path))
2981 make_dir_hier(path);
2983 folder_item_scan(outbox);
2984 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
2986 g_warning(_("can't save message\n"));
2990 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
2991 g_warning(_("can't open mark file\n"));
2995 newmsginfo.msgnum = num;
2996 newmsginfo.flags.perm_flags = 0;
2997 newmsginfo.flags.tmp_flags = 0;
2998 procmsg_write_flags(&newmsginfo, fp);
3006 static gint compose_remove_reedit_target(Compose *compose)
3009 MsgInfo *msginfo = compose->targetinfo;
3011 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3012 if (!msginfo) return -1;
3014 item = msginfo->folder;
3015 g_return_val_if_fail(item != NULL, -1);
3017 folder_item_scan(item);
3018 if (procmsg_msg_exist(msginfo) &&
3019 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3020 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3021 g_warning(_("can't remove the old message\n"));
3030 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3033 gchar *tmpfilename, *queue_path;
3036 gchar buf[BUFFSIZE];
3038 static gboolean lock = FALSE;
3039 PrefsAccount *mailac = NULL, *newsac = NULL;
3041 debug_print(_("queueing message...\n"));
3042 g_return_val_if_fail(compose->account != NULL, -1);
3043 g_return_val_if_fail(compose->orig_account != NULL, -1);
3047 if(!compose_check_for_valid_recipient(compose)) {
3048 alertpanel_error(_("Recipient is not specified."));
3053 if (!compose->to_list && !compose->newsgroup_list) {
3054 g_warning(_("can't get recipient list."));
3055 unlink(tmpfilename);
3060 if (prefs_common.linewrap_at_send)
3061 compose_wrap_line_all(compose);
3063 /* write to temporary file */
3064 tmpfilename = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3065 G_DIR_SEPARATOR, (gint)compose);
3066 if ((fp = fopen(tmpfilename, "w")) == NULL) {
3067 FILE_OP_ERROR(tmpfilename, "fopen");
3068 g_free(tmpfilename);
3071 if (change_file_mode_rw(fp, tmpfilename) < 0) {
3072 FILE_OP_ERROR(tmpfilename, "chmod");
3073 g_warning(_("can't change file mode\n"));
3076 if(compose->to_list) {
3077 if (compose->account->protocol != A_NNTP)
3078 mailac = compose->account;
3079 else if (compose->orig_account->protocol != A_NNTP)
3080 mailac = compose->orig_account;
3081 else if (cur_account && cur_account->protocol != A_NNTP)
3082 mailac = cur_account;
3083 else if (!(mailac = compose_current_mail_account())) {
3084 unlink(tmpfilename);
3086 alertpanel_error(_("No account for sending mails available!"));
3091 if(compose->newsgroup_list) {
3092 if (compose->account->protocol == A_NNTP)
3093 newsac = compose->account;
3094 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3095 unlink(tmpfilename);
3097 alertpanel_error(_("No account for posting news available!"));
3102 /* queueing variables */
3103 fprintf(fp, "AF:\n");
3104 fprintf(fp, "NF:0\n");
3105 fprintf(fp, "PS:10\n");
3106 fprintf(fp, "SRH:1\n");
3107 fprintf(fp, "SFN:\n");
3108 fprintf(fp, "DSR:\n");
3110 fprintf(fp, "MID:<%s>\n", compose->msgid);
3112 fprintf(fp, "MID:\n");
3113 fprintf(fp, "CFG:\n");
3114 fprintf(fp, "PT:0\n");
3115 fprintf(fp, "S:%s\n", compose->account->address);
3116 fprintf(fp, "RQ:\n");
3118 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3120 fprintf(fp, "SSV:\n");
3122 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3124 fprintf(fp, "NSV:\n");
3125 fprintf(fp, "SSH:\n");
3126 /* write recepient list */
3128 if(compose->to_list) {
3129 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3130 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3131 fprintf(fp, ",<%s>", (gchar *)cur->data);
3134 /* write newsgroup list */
3136 if(compose->newsgroup_list) {
3137 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3138 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3139 fprintf(fp, ",%s", (gchar *)cur->data);
3142 /* Sylpheed account IDs */
3144 fprintf(fp, "MAID:%d\n", mailac->account_id);
3147 fprintf(fp, "NAID:%d\n", newsac->account_id);
3152 if (compose->bounce_filename != NULL) {
3153 if (compose_bounce_write_to_file(compose, tmpfilename) < 0) {
3154 unlink(tmpfilename);
3160 if (compose_write_to_file(compose, tmpfilename, FALSE) < 0) {
3161 unlink(tmpfilename);
3168 queue = folder_get_default_queue();
3170 folder_item_scan(queue);
3171 queue_path = folder_item_get_path(queue);
3172 if (!is_dir_exist(queue_path))
3173 make_dir_hier(queue_path);
3174 if ((num = folder_item_add_msg(queue, tmpfilename, TRUE)) < 0) {
3175 g_warning(_("can't queue the message\n"));
3176 unlink(tmpfilename);
3177 g_free(tmpfilename);
3181 g_free(tmpfilename);
3183 if (compose->mode == COMPOSE_REEDIT) {
3184 compose_remove_reedit_target(compose);
3185 if (compose->targetinfo &&
3186 compose->targetinfo->folder != queue)
3187 folderview_update_item
3188 (compose->targetinfo->folder, TRUE);
3191 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
3192 g_warning(_("can't open mark file\n"));
3196 newmsginfo.msgnum = num;
3197 newmsginfo.flags.perm_flags = 0;
3198 newmsginfo.flags.tmp_flags = 0;
3199 procmsg_write_flags(&newmsginfo, fp);
3204 folder_item_scan(queue);
3205 folderview_update_item(queue, TRUE);
3207 if((msgnum != NULL) && (item != NULL)) {
3215 static void compose_write_attach(Compose *compose, FILE *fp)
3218 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3221 gchar filename[BUFFSIZE];
3224 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3226 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
3227 g_warning(_("Can't open file %s\n"), ainfo->file);
3231 fprintf(fp, "\n--%s\n", compose->boundary);
3233 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3234 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3235 fprintf(fp, "Content-Disposition: inline\n");
3237 conv_encode_header(filename, sizeof(filename),
3239 fprintf(fp, "Content-Type: %s;\n"
3241 ainfo->content_type, filename);
3242 fprintf(fp, "Content-Disposition: attachment;\n"
3243 " filename=\"%s\"\n", filename);
3246 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3247 procmime_get_encoding_str(ainfo->encoding));
3249 if (ainfo->encoding == ENC_7BIT) {
3250 gchar buf[BUFFSIZE];
3252 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3257 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3259 while ((len = fread(inbuf, sizeof(gchar),
3260 B64_LINE_SIZE, attach_fp))
3262 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3266 if (len > 0 && feof(attach_fp)) {
3267 to64frombits(outbuf, inbuf, len);
3276 fprintf(fp, "\n--%s--\n", compose->boundary);
3279 #define IS_IN_CUSTOM_HEADER(header) \
3280 (compose->account->add_customhdr && \
3281 custom_header_find(compose->account->customhdr_list, header) != NULL)
3283 static gint compose_write_headers_from_headerlist(Compose *compose,
3287 gchar buf[BUFFSIZE];
3288 gchar *str, *header_w_colon, *trans_hdr;
3289 gboolean first_address;
3291 compose_headerentry *headerentry;
3292 gchar * headerentryname;
3294 if (IS_IN_CUSTOM_HEADER(header)) {
3298 debug_print(_("Writing %s-header\n"), header);
3300 header_w_colon = g_strconcat(header, ":", NULL);
3301 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3303 first_address = TRUE;
3304 for(list = compose->header_list; list; list = list->next) {
3305 headerentry = ((compose_headerentry *)list->data);
3306 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3308 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3309 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3310 Xstrdup_a(str, str, return -1);
3312 if(str[0] != '\0') {
3313 compose_convert_header
3314 (buf, sizeof(buf), str,
3315 strlen(header) + 2);
3317 fprintf(fp, "%s: ", header);
3318 first_address = FALSE;
3322 fprintf(fp, "%s", buf);
3326 if(!first_address) {
3330 g_free(header_w_colon);
3335 static gint compose_write_headers(Compose *compose, FILE *fp,
3336 const gchar *charset, EncodingType encoding,
3339 gchar buf[BUFFSIZE];
3341 /* struct utsname utsbuf; */
3343 g_return_val_if_fail(fp != NULL, -1);
3344 g_return_val_if_fail(charset != NULL, -1);
3345 g_return_val_if_fail(compose->account != NULL, -1);
3346 g_return_val_if_fail(compose->account->address != NULL, -1);
3349 if (compose->account->add_date) {
3350 get_rfc822_date(buf, sizeof(buf));
3351 fprintf(fp, "Date: %s\n", buf);
3355 if (!IS_IN_CUSTOM_HEADER("From")) {
3356 if (compose->account->name && *compose->account->name) {
3357 compose_convert_header
3358 (buf, sizeof(buf), compose->account->name,
3360 fprintf(fp, "From: %s <%s>\n",
3361 buf, compose->account->address);
3363 fprintf(fp, "From: %s\n", compose->account->address);
3367 compose_write_headers_from_headerlist(compose, fp, "To");
3368 #if 0 /* NEW COMPOSE GUI */
3369 if (compose->use_to) {
3370 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3372 Xstrdup_a(str, str, return -1);
3375 compose->to_list = address_list_append
3376 (compose->to_list, str);
3377 if (!IS_IN_CUSTOM_HEADER("To")) {
3378 compose_convert_header
3379 (buf, sizeof(buf), str,
3381 fprintf(fp, "To: %s\n", buf);
3389 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3390 #if 0 /* NEW COMPOSE GUI */
3391 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3393 Xstrdup_a(str, str, return -1);
3397 compose->newsgroup_list =
3398 newsgroup_list_append(compose->newsgroup_list,
3400 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
3401 compose_convert_header(buf, sizeof(buf), str,
3402 strlen("Newsgroups: "));
3403 fprintf(fp, "Newsgroups: %s\n", buf);
3409 compose_write_headers_from_headerlist(compose, fp, "Cc");
3410 #if 0 /* NEW COMPOSE GUI */
3411 if (compose->use_cc) {
3412 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3414 Xstrdup_a(str, str, return -1);
3417 compose->to_list = address_list_append
3418 (compose->to_list, str);
3419 if (!IS_IN_CUSTOM_HEADER("Cc")) {
3420 compose_convert_header
3421 (buf, sizeof(buf), str,
3423 fprintf(fp, "Cc: %s\n", buf);
3430 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3431 #if 0 /* NEW COMPOSE GUI */
3432 if (compose->use_bcc) {
3433 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3435 Xstrdup_a(str, str, return -1);
3438 compose->to_list = address_list_append
3439 (compose->to_list, str);
3440 compose_convert_header(buf, sizeof(buf), str,
3442 fprintf(fp, "Bcc: %s\n", buf);
3449 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3450 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3451 Xstrdup_a(str, str, return -1);
3454 compose_convert_header(buf, sizeof(buf), str,
3455 strlen("Subject: "));
3456 fprintf(fp, "Subject: %s\n", buf);
3461 if (compose->account->gen_msgid) {
3462 compose_generate_msgid(compose, buf, sizeof(buf));
3463 fprintf(fp, "Message-Id: <%s>\n", buf);
3464 compose->msgid = g_strdup(buf);
3468 if (compose->inreplyto && compose->to_list)
3469 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3472 if (compose->references)
3473 fprintf(fp, "References: %s\n", compose->references);
3476 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3477 #if 0 /* NEW COMPOSE GUI */
3478 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3479 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3481 Xstrdup_a(str, str, return -1);
3485 compose_convert_header(buf, sizeof(buf), str,
3486 strlen("Followup-To: "));
3487 fprintf(fp, "Followup-To: %s\n", buf);
3493 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3494 #if 0 /* NEW COMPOSE GUI */
3495 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3496 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3498 Xstrdup_a(str, str, return -1);
3501 compose_convert_header(buf, sizeof(buf), str,
3502 strlen("Reply-To: "));
3503 fprintf(fp, "Reply-To: %s\n", buf);
3509 if (compose->account->organization &&
3510 !IS_IN_CUSTOM_HEADER("Organization")) {
3511 compose_convert_header(buf, sizeof(buf),
3512 compose->account->organization,
3513 strlen("Organization: "));
3514 fprintf(fp, "Organization: %s\n", buf);
3517 /* Program version and system info */
3518 /* uname(&utsbuf); */
3519 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3520 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3522 gtk_major_version, gtk_minor_version, gtk_micro_version,
3524 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3526 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3527 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3529 gtk_major_version, gtk_minor_version, gtk_micro_version,
3531 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3534 /* custom headers */
3535 if (compose->account->add_customhdr) {
3538 for (cur = compose->account->customhdr_list; cur != NULL;
3540 CustomHeader *chdr = (CustomHeader *)cur->data;
3542 if (strcasecmp(chdr->name, "Date") != 0 &&
3543 strcasecmp(chdr->name, "From") != 0 &&
3544 strcasecmp(chdr->name, "To") != 0 &&
3545 strcasecmp(chdr->name, "Sender") != 0 &&
3546 strcasecmp(chdr->name, "Message-Id") != 0 &&
3547 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3548 strcasecmp(chdr->name, "References") != 0 &&
3549 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3550 strcasecmp(chdr->name, "Content-Type") != 0 &&
3551 strcasecmp(chdr->name, "Content-Transfer-Encoding") != 0)
3552 compose_convert_header
3554 chdr->value ? chdr->value : "",
3555 strlen(chdr->name) + 2);
3556 fprintf(fp, "%s: %s\n", chdr->name, buf);
3561 fprintf(fp, "Mime-Version: 1.0\n");
3562 if (compose_use_attach(compose)) {
3563 get_rfc822_date(buf, sizeof(buf));
3564 subst_char(buf, ' ', '_');
3565 subst_char(buf, ',', '_');
3566 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3567 buf, (guint)compose);
3569 "Content-Type: multipart/mixed;\n"
3570 " boundary=\"%s\"\n", compose->boundary);
3572 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3573 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3574 procmime_get_encoding_str(encoding));
3577 /* Request Return Receipt */
3578 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3579 if (compose->return_receipt) {
3580 if (compose->account->name
3581 && *compose->account->name) {
3582 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3583 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3585 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3589 /* separator between header and body */
3595 #undef IS_IN_CUSTOM_HEADER
3597 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3600 g_return_if_fail(src != NULL);
3601 g_return_if_fail(dest != NULL);
3603 if (len < 1) return;
3607 if (is_ascii_str(src)) {
3608 strncpy2(dest, src, len);
3609 dest[len - 1] = '\0';
3612 conv_encode_header(dest, len, src, header_len);
3615 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3624 if (compose->account && compose->account->address &&
3625 *compose->account->address) {
3626 if (strchr(compose->account->address, '@'))
3627 addr = g_strdup(compose->account->address);
3629 addr = g_strconcat(compose->account->address, "@",
3630 get_domain_name(), NULL);
3632 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3635 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3636 lt->tm_year + 1900, lt->tm_mon + 1,
3637 lt->tm_mday, lt->tm_hour,
3638 lt->tm_min, lt->tm_sec,
3639 (guint)random(), addr);
3641 debug_print(_("generated Message-ID: %s\n"), buf);
3647 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3648 GtkWidget **entry, gint *count,
3649 const gchar *label_str,
3650 gboolean is_addr_entry)
3654 if (GTK_TABLE(table)->nrows < (*count) + 1)
3655 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3657 *hbox = gtk_hbox_new(FALSE, 0);
3658 label = gtk_label_new
3659 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3660 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3661 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3663 *entry = gtk_entry_new();
3665 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3666 #if 0 /* NEW COMPOSE GUI */
3667 if (GTK_TABLE(table)->nrows > (*count) + 1)
3668 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
3672 address_completion_register_entry(GTK_ENTRY(*entry));
3677 static void compose_create_header_entry(Compose *compose) {
3678 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3682 GList *combo_list = NULL;
3683 gchar **string, *header;
3684 compose_headerentry *headerentry = g_new0(compose_headerentry, 1);
3687 combo = gtk_combo_new();
3689 while(*string != NULL) {
3690 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
3693 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
3694 g_list_free(combo_list);
3695 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
3696 gtk_widget_show(combo);
3697 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
3698 if(compose->header_last) {
3699 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
3701 switch(compose->account->protocol) {
3703 header = _("Newsgroups:");
3710 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
3713 entry = gtk_entry_new();
3714 gtk_widget_show(entry);
3715 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);
3717 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
3718 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
3720 address_completion_register_entry(GTK_ENTRY(entry));
3722 headerentry->compose = compose;
3723 headerentry->combo = combo;
3724 headerentry->entry = entry;
3725 headerentry->headernum = compose->header_nextrow;
3727 compose->header_nextrow++;
3728 compose->header_last = headerentry;
3731 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text) {
3732 compose_headerentry *last_header;
3734 last_header = compose->header_last;
3736 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
3737 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
3740 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
3746 GtkWidget *handlebox;
3748 GtkWidget *notebook;
3752 GtkWidget *table_vbox;
3754 GtkWidget *from_optmenu_hbox;
3755 #if 0 /* NEW COMPOSE GUI */
3756 GtkWidget *to_entry;
3758 GtkWidget *newsgroups_entry;
3759 GtkWidget *newsgroups_hbox;
3761 GtkWidget *header_scrolledwin;
3762 GtkWidget *header_table;
3763 GtkWidget *subject_entry;
3764 #if 0 /* NEW COMPOSE GUI */
3765 GtkWidget *cc_entry;
3767 GtkWidget *bcc_entry;
3768 GtkWidget *bcc_hbox;
3769 GtkWidget *reply_entry;
3770 GtkWidget *reply_hbox;
3771 GtkWidget *followup_entry;
3772 GtkWidget *followup_hbox;
3776 GtkWidget *attach_scrwin;
3777 GtkWidget *attach_clist;
3779 GtkWidget *edit_vbox;
3780 GtkWidget *ruler_hbox;
3782 GtkWidget *scrolledwin;
3788 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
3789 guint n_menu_entries;
3790 GtkStyle *style, *new_style;
3793 gboolean success[1];
3795 GtkWidget *popupmenu;
3796 GtkWidget *menuitem;
3797 GtkItemFactory *popupfactory;
3798 GtkItemFactory *ifactory;
3799 GtkWidget *tmpl_menu;
3805 GtkPspell * gtkpspell = NULL;
3808 g_return_val_if_fail(account != NULL, NULL);
3810 debug_print(_("Creating compose window...\n"));
3811 compose = g_new0(Compose, 1);
3813 compose->account = account;
3814 compose->orig_account = account;
3816 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
3817 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
3818 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
3819 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
3820 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
3821 gtk_signal_connect(GTK_OBJECT(window), "destroy",
3822 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
3823 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
3824 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
3825 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
3826 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
3827 gtk_widget_realize(window);
3829 gtkut_widget_set_composer_icon(window);
3831 vbox = gtk_vbox_new(FALSE, 0);
3832 gtk_container_add(GTK_CONTAINER(window), vbox);
3834 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
3835 menubar = menubar_create(window, compose_entries,
3836 n_menu_entries, "<Compose>", compose);
3837 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
3839 handlebox = gtk_handle_box_new();
3840 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
3842 compose_toolbar_create(compose, handlebox);
3844 vbox2 = gtk_vbox_new(FALSE, 2);
3845 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
3846 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
3848 table_vbox = gtk_vbox_new(FALSE, 0);
3849 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
3850 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
3854 notebook = gtk_notebook_new();
3855 gtk_widget_set_usize(notebook, -1, 180);
3856 gtk_widget_show(notebook);
3858 /* header labels and entries */
3859 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
3860 gtk_widget_show(header_scrolledwin);
3861 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
3862 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), header_scrolledwin, gtk_label_new(_("Header")));
3864 header_table = gtk_table_new(2, 2, FALSE);
3865 gtk_widget_show(header_table);
3866 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
3867 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
3870 /* option menu for selecting accounts */
3871 hbox = gtk_hbox_new(FALSE, 0);
3872 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
3873 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3874 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
3876 from_optmenu_hbox = compose_account_option_menu_create(compose);
3877 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
3878 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
3879 #if 0 /* NEW COMPOSE GUI */
3880 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
3885 compose_add_entry_field(header_table, &hbox, &subject_entry, &count,
3888 compose->header_table = header_table;
3889 compose->header_list = NULL;
3890 compose->header_nextrow = count;
3892 compose_create_header_entry(compose);
3894 #if 0 /* NEW COMPOSE GUI */
3895 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
3897 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
3898 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
3899 &count, "Newsgroups:", FALSE);
3900 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
3902 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
3904 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
3906 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
3907 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
3909 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
3910 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
3912 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
3913 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
3914 "Followup-To:", FALSE);
3915 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
3917 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
3919 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
3920 GTK_SIGNAL_FUNC(to_activated), compose);
3921 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
3922 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
3923 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
3924 GTK_SIGNAL_FUNC(subject_activated), compose);
3925 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
3926 GTK_SIGNAL_FUNC(cc_activated), compose);
3927 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
3928 GTK_SIGNAL_FUNC(bcc_activated), compose);
3929 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
3930 GTK_SIGNAL_FUNC(replyto_activated), compose);
3931 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
3932 GTK_SIGNAL_FUNC(followupto_activated), compose);
3934 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
3935 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3936 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
3937 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3938 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
3939 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3940 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
3941 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3942 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
3943 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3944 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
3945 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3946 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
3947 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3950 /* attachment list */
3951 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
3952 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), attach_scrwin, gtk_label_new(_("Attachments")));
3953 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
3954 GTK_POLICY_AUTOMATIC,
3956 gtk_widget_set_usize(attach_scrwin, -1, 80);
3958 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
3959 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
3961 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
3962 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
3963 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
3964 GTK_SELECTION_EXTENDED);
3965 for (i = 0; i < N_ATTACH_COLS; i++)
3966 GTK_WIDGET_UNSET_FLAGS
3967 (GTK_CLIST(attach_clist)->column[i].button,
3969 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
3971 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
3972 GTK_SIGNAL_FUNC(attach_selected), compose);
3973 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
3974 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
3975 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
3976 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
3979 gtk_drag_dest_set(attach_clist,
3980 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
3982 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
3983 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
3987 edit_vbox = gtk_vbox_new(FALSE, 0);
3988 #if 0 /* NEW COMPOSE GUI */
3989 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
3993 ruler_hbox = gtk_hbox_new(FALSE, 0);
3994 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
3996 ruler = gtk_shruler_new();
3997 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
3998 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4000 gtk_widget_set_usize(ruler_hbox, 1, -1);
4003 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4004 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4005 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4006 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4007 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4009 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4010 (GTK_SCROLLED_WINDOW(scrolledwin)),
4011 gtk_scrolled_window_get_vadjustment
4012 (GTK_SCROLLED_WINDOW(scrolledwin)));
4013 GTK_STEXT(text)->default_tab_width = 8;
4014 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4016 if (prefs_common.block_cursor) {
4017 GTK_STEXT(text)->cursor_type = STEXT_CURSOR_BLOCK;
4020 if (prefs_common.smart_wrapping) {
4021 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4022 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4025 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4027 gtk_signal_connect(GTK_OBJECT(text), "changed",
4028 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4029 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4030 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4031 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4032 GTK_SIGNAL_FUNC(compose_button_press_cb),
4035 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4036 GTK_SIGNAL_FUNC(compose_key_press_cb),
4039 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4040 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4044 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4046 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4047 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4050 if (prefs_common.enable_pspell) {
4051 gtkpspell = gtkpspell_new_with_config(gtkpspellconfig,
4052 prefs_common.pspell_path,
4053 prefs_common.dictionary,
4055 conv_get_current_charset_str());
4056 if (gtkpspell == NULL)
4057 prefs_common.enable_pspell = FALSE;
4059 gtkpspell_attach(gtkpspell, GTK_STEXT(text));
4062 gtk_widget_show_all(vbox);
4064 /* pane between attach clist and text */
4065 paned = gtk_vpaned_new();
4066 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4067 gtk_paned_add1(GTK_PANED(paned), notebook);
4068 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4069 gtk_widget_show_all(paned);
4071 style = gtk_widget_get_style(text);
4073 /* workaround for the slow down of GtkText when using Pixmap theme */
4074 if (style->engine) {
4075 GtkThemeEngine *engine;
4077 engine = style->engine;
4078 style->engine = NULL;
4079 new_style = gtk_style_copy(style);
4080 style->engine = engine;
4082 new_style = gtk_style_copy(style);
4084 if (prefs_common.textfont) {
4087 charset = conv_get_current_charset();
4088 if (MB_CUR_MAX == 1) {
4091 Xstrdup_a(fontstr, prefs_common.textfont, );
4092 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4094 font = gdk_font_load(fontstr);
4096 font = gdk_fontset_load(prefs_common.textfont);
4098 gdk_font_unref(new_style->font);
4099 new_style->font = font;
4103 gtk_widget_set_style(text, new_style);
4105 color[0] = quote_color;
4106 cmap = gdk_window_get_colormap(window->window);
4107 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4108 if (success[0] == FALSE) {
4109 g_warning("Compose: color allocation failed.\n");
4110 style = gtk_widget_get_style(text);
4111 quote_color = style->black;
4114 n_entries = sizeof(compose_popup_entries) /
4115 sizeof(compose_popup_entries[0]);
4116 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4117 "<Compose>", &popupfactory,
4120 ifactory = gtk_item_factory_from_widget(menubar);
4121 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4122 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4124 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tool/Template");
4125 #if 0 /* NEW COMPOSE GUI */
4126 if (account->protocol == A_NNTP) {
4127 gtk_widget_hide(to_hbox);
4128 gtk_widget_hide(to_entry);
4129 gtk_widget_hide(cc_hbox);
4130 gtk_widget_hide(cc_entry);
4131 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4132 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4134 gtk_widget_hide(newsgroups_hbox);
4135 gtk_widget_hide(newsgroups_entry);
4136 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4138 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
4142 switch (prefs_common.toolbar_style) {
4144 gtk_widget_hide(handlebox);
4147 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4151 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4155 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4160 gtk_widget_show(window);
4162 address_completion_start(window);
4164 compose->window = window;
4165 compose->vbox = vbox;
4166 compose->menubar = menubar;
4167 compose->handlebox = handlebox;
4169 compose->vbox2 = vbox2;
4171 compose->table_vbox = table_vbox;
4172 compose->table = table;
4173 #if 0 /* NEW COMPOSE GUI */
4174 compose->to_hbox = to_hbox;
4175 compose->to_entry = to_entry;
4176 compose->newsgroups_hbox = newsgroups_hbox;
4177 compose->newsgroups_entry = newsgroups_entry;
4179 compose->subject_entry = subject_entry;
4180 #if 0 /* NEW COMPOSE GUI */
4181 compose->cc_hbox = cc_hbox;
4182 compose->cc_entry = cc_entry;
4183 compose->bcc_hbox = bcc_hbox;
4184 compose->bcc_entry = bcc_entry;
4185 compose->reply_hbox = reply_hbox;
4186 compose->reply_entry = reply_entry;
4187 compose->followup_hbox = followup_hbox;
4188 compose->followup_entry = followup_entry;
4190 compose->paned = paned;
4192 compose->attach_scrwin = attach_scrwin;
4193 compose->attach_clist = attach_clist;
4195 compose->edit_vbox = edit_vbox;
4196 compose->ruler_hbox = ruler_hbox;
4197 compose->ruler = ruler;
4198 compose->scrolledwin = scrolledwin;
4199 compose->text = text;
4201 compose->focused_editable = NULL;
4203 compose->popupmenu = popupmenu;
4204 compose->popupfactory = popupfactory;
4206 compose->tmpl_menu = tmpl_menu;
4208 compose->mode = mode;
4210 compose->targetinfo = NULL;
4211 compose->replyinfo = NULL;
4213 compose->replyto = NULL;
4214 compose->mailinglist = NULL;
4216 compose->bcc = NULL;
4217 compose->followup_to = NULL;
4218 compose->inreplyto = NULL;
4219 compose->references = NULL;
4220 compose->msgid = NULL;
4221 compose->boundary = NULL;
4224 compose->use_signing = FALSE;
4225 compose->use_encryption = FALSE;
4226 #endif /* USE_GPGME */
4228 compose->modified = FALSE;
4230 compose->return_receipt = FALSE;
4232 compose->to_list = NULL;
4233 compose->newsgroup_list = NULL;
4235 compose->exteditor_file = NULL;
4236 compose->exteditor_pid = -1;
4237 compose->exteditor_readdes = -1;
4238 compose->exteditor_tag = -1;
4240 compose->bounce_filename = NULL;
4242 compose_set_title(compose);
4244 #if 0 /* NEW COMPOSE GUI */
4245 compose->use_bcc = FALSE;
4246 compose->use_replyto = FALSE;
4247 compose->use_followupto = FALSE;
4251 compose->gtkpspell = gtkpspell;
4254 #if 0 /* NEW COMPOSE GUI */
4255 if (account->protocol != A_NNTP) {
4256 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4257 gtk_check_menu_item_set_active
4258 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4259 gtk_widget_set_sensitive(menuitem, FALSE);
4260 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4261 gtk_check_menu_item_set_active
4262 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4263 gtk_widget_set_sensitive(menuitem, FALSE);
4266 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4267 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4268 #if 0 /* NEW COMPOSE GUI */
4269 compose->use_cc = TRUE;
4270 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4271 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4272 gtk_check_menu_item_set_active
4273 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4276 if (account->set_autobcc) {
4277 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4278 #if 0 /* NEW COMPOSE GUI */
4279 compose->use_bcc = TRUE;
4280 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
4281 gtk_check_menu_item_set_active
4282 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4283 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4284 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4288 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4289 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4290 #if 0 /* NEW COMPOSE GUI */
4291 compose->use_replyto = TRUE;
4292 menuitem = gtk_item_factory_get_item(ifactory,
4293 "/Message/Reply to");
4294 gtk_check_menu_item_set_active
4295 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4296 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4297 account->auto_replyto);
4300 if (account->protocol != A_NNTP) {
4301 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), _("To:"));
4303 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), _("Newsgroups:"));
4306 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
4307 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4308 prefs_common.show_ruler);
4311 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4312 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4313 prefs_common.default_sign);
4314 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4315 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4316 prefs_common.default_encrypt);
4317 #endif /* USE_GPGME */
4319 addressbook_set_target_compose(compose);
4320 compose_set_template_menu(compose);
4322 compose_list = g_list_append(compose_list, compose);
4324 #if 0 /* NEW COMPOSE GUI */
4325 compose->use_to = FALSE;
4326 compose->use_cc = FALSE;
4327 compose->use_attach = TRUE;
4330 #if 0 /* NEW COMPOSE GUI */
4331 if (!compose->use_bcc) {
4332 gtk_widget_hide(bcc_hbox);
4333 gtk_widget_hide(bcc_entry);
4334 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4336 if (!compose->use_replyto) {
4337 gtk_widget_hide(reply_hbox);
4338 gtk_widget_hide(reply_entry);
4339 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4341 if (!compose->use_followupto) {
4342 gtk_widget_hide(followup_hbox);
4343 gtk_widget_hide(followup_entry);
4344 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4347 if (!prefs_common.show_ruler)
4348 gtk_widget_hide(ruler_hbox);
4350 select_account(compose, account);
4355 #include "pixmaps/stock_mail_send.xpm"
4356 #include "pixmaps/stock_mail_send_queue.xpm"
4357 #include "pixmaps/stock_mail.xpm"
4358 #include "pixmaps/stock_paste.xpm"
4359 #include "pixmaps/stock_mail_attach.xpm"
4360 #include "pixmaps/stock_mail_compose.xpm"
4361 #include "pixmaps/linewrap.xpm"
4362 #include "pixmaps/tb_address_book.xpm"
4364 #define CREATE_TOOLBAR_ICON(xpm_d) \
4366 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
4367 &container->style->white, \
4369 icon_wid = gtk_pixmap_new(icon, mask); \
4372 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4377 GtkWidget *icon_wid;
4378 GtkWidget *send_btn;
4379 GtkWidget *sendl_btn;
4380 GtkWidget *draft_btn;
4381 GtkWidget *insert_btn;
4382 GtkWidget *attach_btn;
4384 GtkWidget *exteditor_btn;
4385 GtkWidget *linewrap_btn;
4386 GtkWidget *addrbook_btn;
4388 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4390 gtk_container_add(GTK_CONTAINER(container), toolbar);
4391 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4392 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4393 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4394 GTK_TOOLBAR_SPACE_LINE);
4396 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
4397 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4401 icon_wid, toolbar_send_cb, compose);
4403 CREATE_TOOLBAR_ICON(stock_mail_send_queue_xpm);
4404 /* CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm); */
4405 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4407 _("Put into queue folder and send later"),
4409 icon_wid, toolbar_send_later_cb,
4412 CREATE_TOOLBAR_ICON(stock_mail_xpm);
4413 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4415 _("Save to draft folder"),
4417 icon_wid, toolbar_draft_cb,
4420 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4422 CREATE_TOOLBAR_ICON(stock_paste_xpm);
4423 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4427 icon_wid, toolbar_insert_cb,
4430 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
4431 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4435 icon_wid, toolbar_attach_cb,
4438 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4440 CREATE_TOOLBAR_ICON(stock_mail_xpm);
4441 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4443 _("Insert signature"),
4445 icon_wid, toolbar_sig_cb, compose);
4447 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4449 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
4450 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4452 _("Edit with external editor"),
4455 toolbar_ext_editor_cb,
4458 CREATE_TOOLBAR_ICON(linewrap_xpm);
4459 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4461 _("Wrap current paragraph"),
4464 toolbar_linewrap_cb,
4467 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4469 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
4470 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4474 icon_wid, toolbar_address_cb,
4477 compose->toolbar = toolbar;
4478 compose->send_btn = send_btn;
4479 compose->sendl_btn = sendl_btn;
4480 compose->draft_btn = draft_btn;
4481 compose->insert_btn = insert_btn;
4482 compose->attach_btn = attach_btn;
4483 compose->sig_btn = sig_btn;
4484 compose->exteditor_btn = exteditor_btn;
4485 compose->linewrap_btn = linewrap_btn;
4486 compose->addrbook_btn = addrbook_btn;
4488 gtk_widget_show_all(toolbar);
4491 #undef CREATE_TOOLBAR_ICON
4493 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4499 gint num = 0, def_menu = 0;
4501 accounts = account_get_list();
4502 g_return_val_if_fail(accounts != NULL, NULL);
4504 hbox = gtk_hbox_new(FALSE, 0);
4505 optmenu = gtk_option_menu_new();
4506 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4507 menu = gtk_menu_new();
4509 for (; accounts != NULL; accounts = accounts->next, num++) {
4510 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4511 GtkWidget *menuitem;
4514 if (ac == compose->account) def_menu = num;
4516 name = g_strdup_printf("%s: %s <%s>",
4517 ac->account_name, ac->name, ac->address);
4518 MENUITEM_ADD(menu, menuitem, name, ac);
4520 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4521 GTK_SIGNAL_FUNC(account_activated),
4525 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4526 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4531 static void compose_set_template_menu(Compose *compose)
4533 GSList *tmpl_list, *cur;
4537 tmpl_list = template_get_config();
4539 menu = gtk_menu_new();
4541 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
4542 Template *tmpl = (Template *)cur->data;
4544 item = gtk_menu_item_new_with_label(tmpl->name);
4545 gtk_menu_append(GTK_MENU(menu), item);
4546 gtk_signal_connect(GTK_OBJECT(item), "activate",
4547 GTK_SIGNAL_FUNC(compose_template_activate_cb),
4549 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
4550 gtk_widget_show(item);
4553 gtk_widget_show(menu);
4554 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
4557 void compose_reflect_prefs_all(void)
4562 for (cur = compose_list; cur != NULL; cur = cur->next) {
4563 compose = (Compose *)cur->data;
4564 compose_set_template_menu(compose);
4568 static void compose_template_apply(Compose *compose, const gchar *tmpl_str)
4573 if (!tmpl_str) return;
4575 gtk_stext_freeze(GTK_STEXT(compose->text));
4577 if (compose->replyinfo == NULL) {
4580 memset(&dummyinfo, 0, sizeof(MsgInfo));
4581 parsed_str = compose_quote_fmt(compose, &dummyinfo, tmpl_str,
4584 if (prefs_common.quotemark && *prefs_common.quotemark)
4585 qmark = prefs_common.quotemark;
4589 parsed_str = compose_quote_fmt(compose, compose->replyinfo, tmpl_str,
4593 if (parsed_str && prefs_common.auto_sig)
4594 compose_insert_sig(compose);
4596 gtk_stext_thaw(GTK_STEXT(compose->text));
4599 static void compose_destroy(Compose *compose)
4602 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4605 /* NOTE: address_completion_end() does nothing with the window
4606 * however this may change. */
4607 address_completion_end(compose->window);
4609 slist_free_strings(compose->to_list);
4610 g_slist_free(compose->to_list);
4611 slist_free_strings(compose->newsgroup_list);
4612 g_slist_free(compose->newsgroup_list);
4613 slist_free_strings(compose->header_list);
4614 g_slist_free(compose->header_list);
4616 procmsg_msginfo_free(compose->targetinfo);
4617 procmsg_msginfo_free(compose->replyinfo);
4619 g_free(compose->replyto);
4620 g_free(compose->cc);
4621 g_free(compose->bcc);
4622 g_free(compose->newsgroups);
4623 g_free(compose->followup_to);
4625 g_free(compose->inreplyto);
4626 g_free(compose->references);
4627 g_free(compose->msgid);
4628 g_free(compose->boundary);
4630 if (compose->bounce_filename)
4631 g_free(compose->bounce_filename);
4633 g_free(compose->exteditor_file);
4635 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
4637 compose_attach_info_free(ainfo);
4639 if (addressbook_get_target_compose() == compose)
4640 addressbook_set_target_compose(NULL);
4642 prefs_common.compose_width = compose->scrolledwin->allocation.width;
4643 prefs_common.compose_height = compose->window->allocation.height;
4645 gtk_widget_destroy(compose->paned);
4649 compose_list = g_list_remove(compose_list, compose);
4652 static void compose_attach_info_free(AttachInfo *ainfo)
4654 g_free(ainfo->file);
4655 g_free(ainfo->content_type);
4656 g_free(ainfo->name);
4660 static void compose_attach_remove_selected(Compose *compose)
4662 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4666 while (clist->selection != NULL) {
4667 row = GPOINTER_TO_INT(clist->selection->data);
4668 ainfo = gtk_clist_get_row_data(clist, row);
4669 compose_attach_info_free(ainfo);
4670 gtk_clist_remove(clist, row);
4674 static struct _AttachProperty
4677 GtkWidget *mimetype_entry;
4678 GtkWidget *encoding_optmenu;
4679 GtkWidget *path_entry;
4680 GtkWidget *filename_entry;
4682 GtkWidget *cancel_btn;
4685 static void compose_attach_property(Compose *compose)
4687 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4690 GtkOptionMenu *optmenu;
4691 static gboolean cancelled;
4693 if (!clist->selection) return;
4694 row = GPOINTER_TO_INT(clist->selection->data);
4696 ainfo = gtk_clist_get_row_data(clist, row);
4699 if (!attach_prop.window)
4700 compose_attach_property_create(&cancelled);
4701 gtk_widget_grab_focus(attach_prop.ok_btn);
4702 gtk_widget_show(attach_prop.window);
4703 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
4705 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
4706 if (ainfo->encoding == ENC_UNKNOWN)
4707 gtk_option_menu_set_history(optmenu, ENC_BASE64);
4709 gtk_option_menu_set_history(optmenu, ainfo->encoding);
4711 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
4712 ainfo->content_type ? ainfo->content_type : "");
4713 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
4714 ainfo->file ? ainfo->file : "");
4715 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
4716 ainfo->name ? ainfo->name : "");
4720 gchar *cnttype = NULL;
4724 GtkWidget *menuitem;
4729 if (cancelled == TRUE) {
4730 gtk_widget_hide(attach_prop.window);
4734 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
4735 if (*text != '\0') {
4738 text = g_strstrip(g_strdup(text));
4739 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
4740 cnttype = g_strdup(text);
4743 alertpanel_error(_("Invalid MIME type."));
4749 menu = gtk_option_menu_get_menu(optmenu);
4750 menuitem = gtk_menu_get_active(GTK_MENU(menu));
4751 ainfo->encoding = GPOINTER_TO_INT
4752 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
4754 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
4755 if (*text != '\0') {
4756 if (is_file_exist(text) &&
4757 (size = get_file_size(text)) > 0)
4758 file = g_strdup(text);
4761 (_("File doesn't exist or is empty."));
4767 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
4768 if (*text != '\0') {
4769 g_free(ainfo->name);
4770 ainfo->name = g_strdup(text);
4774 g_free(ainfo->content_type);
4775 ainfo->content_type = cnttype;
4778 g_free(ainfo->file);
4784 gtk_clist_set_text(clist, row, COL_MIMETYPE,
4785 ainfo->content_type);
4786 gtk_clist_set_text(clist, row, COL_SIZE,
4787 to_human_readable(ainfo->size));
4788 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
4790 gtk_widget_hide(attach_prop.window);
4795 #define SET_LABEL_AND_ENTRY(str, entry, top) \
4797 label = gtk_label_new(str); \
4798 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
4799 GTK_FILL, 0, 0, 0); \
4800 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
4802 entry = gtk_entry_new(); \
4803 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
4804 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
4807 static void compose_attach_property_create(gboolean *cancelled)
4813 GtkWidget *mimetype_entry;
4816 GtkWidget *optmenu_menu;
4817 GtkWidget *menuitem;
4818 GtkWidget *path_entry;
4819 GtkWidget *filename_entry;
4822 GtkWidget *cancel_btn;
4823 GList *mime_type_list, *strlist;
4825 debug_print("Creating attach_property window...\n");
4827 window = gtk_window_new(GTK_WINDOW_DIALOG);
4828 gtk_widget_set_usize(window, 480, -1);
4829 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
4830 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
4831 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
4832 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
4833 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4834 GTK_SIGNAL_FUNC(attach_property_delete_event),
4836 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
4837 GTK_SIGNAL_FUNC(attach_property_key_pressed),
4840 vbox = gtk_vbox_new(FALSE, 8);
4841 gtk_container_add(GTK_CONTAINER(window), vbox);
4843 table = gtk_table_new(4, 2, FALSE);
4844 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
4845 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
4846 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
4848 label = gtk_label_new(_("MIME type"));
4849 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
4851 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
4852 mimetype_entry = gtk_combo_new();
4853 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
4854 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
4856 /* stuff with list */
4857 mime_type_list = procmime_get_mime_type_list();
4859 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
4860 MimeType *type = (MimeType *) mime_type_list->data;
4861 strlist = g_list_append(strlist,
4862 g_strdup_printf("%s/%s",
4863 type->type, type->sub_type));
4866 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
4868 for (mime_type_list = strlist; mime_type_list != NULL;
4869 mime_type_list = mime_type_list->next)
4870 g_free(mime_type_list->data);
4871 g_list_free(strlist);
4873 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
4875 label = gtk_label_new(_("Encoding"));
4876 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
4878 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
4880 hbox = gtk_hbox_new(FALSE, 0);
4881 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
4882 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
4884 optmenu = gtk_option_menu_new();
4885 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4887 optmenu_menu = gtk_menu_new();
4888 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
4889 gtk_widget_set_sensitive(menuitem, FALSE);
4890 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
4891 gtk_widget_set_sensitive(menuitem, FALSE);
4892 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
4893 gtk_widget_set_sensitive(menuitem, FALSE);
4894 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
4896 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
4898 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
4899 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
4901 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
4902 &cancel_btn, _("Cancel"), NULL, NULL);
4903 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
4904 gtk_widget_grab_default(ok_btn);
4906 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
4907 GTK_SIGNAL_FUNC(attach_property_ok),
4909 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
4910 GTK_SIGNAL_FUNC(attach_property_cancel),
4913 gtk_widget_show_all(vbox);
4915 attach_prop.window = window;
4916 attach_prop.mimetype_entry = mimetype_entry;
4917 attach_prop.encoding_optmenu = optmenu;
4918 attach_prop.path_entry = path_entry;
4919 attach_prop.filename_entry = filename_entry;
4920 attach_prop.ok_btn = ok_btn;
4921 attach_prop.cancel_btn = cancel_btn;
4924 #undef SET_LABEL_AND_ENTRY
4926 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
4932 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
4938 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
4939 gboolean *cancelled)
4947 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
4948 gboolean *cancelled)
4950 if (event && event->keyval == GDK_Escape) {
4956 static void compose_exec_ext_editor(Compose *compose)
4962 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
4963 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
4965 if (pipe(pipe_fds) < 0) {
4970 if ((pid = fork()) < 0) {
4976 /* close the write side of the pipe */
4979 compose->exteditor_file = g_strdup(tmp);
4980 compose->exteditor_pid = pid;
4981 compose->exteditor_readdes = pipe_fds[0];
4983 compose_set_ext_editor_sensitive(compose, FALSE);
4985 compose->exteditor_tag =
4986 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
4987 compose_input_cb, compose);
4988 } else { /* process-monitoring process */
4994 /* close the read side of the pipe */
4997 if (compose_write_body_to_file(compose, tmp) < 0) {
4998 fd_write(pipe_fds[1], "2\n", 2);
5002 pid_ed = compose_exec_ext_editor_real(tmp);
5004 fd_write(pipe_fds[1], "1\n", 2);
5008 /* wait until editor is terminated */
5009 waitpid(pid_ed, NULL, 0);
5011 fd_write(pipe_fds[1], "0\n", 2);
5018 static gint compose_exec_ext_editor_real(const gchar *file)
5020 static gchar *def_cmd = "emacs %s";
5026 g_return_val_if_fail(file != NULL, -1);
5028 if ((pid = fork()) < 0) {
5033 if (pid != 0) return pid;
5035 /* grandchild process */
5037 if (setpgid(0, getppid()))
5040 if (prefs_common.ext_editor_cmd &&
5041 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5042 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5043 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5045 if (prefs_common.ext_editor_cmd)
5046 g_warning(_("External editor command line is invalid: `%s'\n"),
5047 prefs_common.ext_editor_cmd);
5048 g_snprintf(buf, sizeof(buf), def_cmd, file);
5051 cmdline = g_strsplit(buf, " ", 1024);
5052 execvp(cmdline[0], cmdline);
5055 g_strfreev(cmdline);
5060 static gboolean compose_ext_editor_kill(Compose *compose)
5062 pid_t pgid = compose->exteditor_pid * -1;
5065 ret = kill(pgid, 0);
5067 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5071 msg = g_strdup_printf
5072 (_("The external editor is still working.\n"
5073 "Force terminating the process?\n"
5074 "process group id: %d"), -pgid);
5075 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5078 if (val == G_ALERTDEFAULT) {
5079 gdk_input_remove(compose->exteditor_tag);
5080 close(compose->exteditor_readdes);
5082 if (kill(pgid, SIGTERM) < 0) perror("kill");
5083 waitpid(compose->exteditor_pid, NULL, 0);
5085 g_warning(_("Terminated process group id: %d"), -pgid);
5086 g_warning(_("Temporary file: %s"),
5087 compose->exteditor_file);
5089 compose_set_ext_editor_sensitive(compose, TRUE);
5091 g_free(compose->exteditor_file);
5092 compose->exteditor_file = NULL;
5093 compose->exteditor_pid = -1;
5094 compose->exteditor_readdes = -1;
5095 compose->exteditor_tag = -1;
5103 static void compose_input_cb(gpointer data, gint source,
5104 GdkInputCondition condition)
5107 Compose *compose = (Compose *)data;
5110 debug_print(_("Compose: input from monitoring process\n"));
5112 gdk_input_remove(compose->exteditor_tag);
5115 if (read(source, &buf[i], 1) < 1) {
5119 if (buf[i] == '\n') {
5124 if (i == sizeof(buf) - 1)
5128 waitpid(compose->exteditor_pid, NULL, 0);
5130 if (buf[0] == '0') { /* success */
5131 GtkSText *text = GTK_STEXT(compose->text);
5133 gtk_stext_freeze(text);
5134 gtk_stext_set_point(text, 0);
5135 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5136 compose_insert_file(compose, compose->exteditor_file);
5137 compose_changed_cb(NULL, compose);
5138 gtk_stext_thaw(text);
5140 if (unlink(compose->exteditor_file) < 0)
5141 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5142 } else if (buf[0] == '1') { /* failed */
5143 g_warning(_("Couldn't exec external editor\n"));
5144 if (unlink(compose->exteditor_file) < 0)
5145 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5146 } else if (buf[0] == '2') {
5147 g_warning(_("Couldn't write to file\n"));
5148 } else if (buf[0] == '3') {
5149 g_warning(_("Pipe read failed\n"));
5154 compose_set_ext_editor_sensitive(compose, TRUE);
5156 g_free(compose->exteditor_file);
5157 compose->exteditor_file = NULL;
5158 compose->exteditor_pid = -1;
5159 compose->exteditor_readdes = -1;
5160 compose->exteditor_tag = -1;
5163 static void compose_set_ext_editor_sensitive(Compose *compose,
5166 GtkItemFactory *ifactory;
5168 ifactory = gtk_item_factory_from_widget(compose->menubar);
5170 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5171 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5172 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5174 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5175 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5176 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5177 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5178 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5181 gtk_widget_set_sensitive(compose->text, sensitive);
5182 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5183 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5184 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5185 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5186 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5187 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5188 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5191 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5195 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5196 cursor_pos = MAX(cursor_pos, 0);
5201 /* callback functions */
5203 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5204 * includes "non-client" (windows-izm) in calculation, so this calculation
5205 * may not be accurate.
5207 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5208 GtkAllocation *allocation,
5209 GtkSHRuler *shruler)
5211 if (prefs_common.show_ruler) {
5213 gint line_width_in_chars;
5215 char_width = gtkut_get_font_width
5216 (GTK_WIDGET(widget)->style->font);
5217 line_width_in_chars =
5218 (allocation->width - allocation->x) / char_width;
5220 /* got the maximum */
5221 gtk_ruler_set_range(GTK_RULER(shruler),
5222 0.0, line_width_in_chars,
5223 calc_cursor_xpos(GTK_STEXT(widget),
5226 /*line_width_in_chars*/ char_width);
5232 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5234 compose_send_cb(data, 0, NULL);
5237 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5239 compose_send_later_cb(data, 0, NULL);
5242 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5244 compose_draft_cb(data, 0, NULL);
5247 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5249 compose_insert_file_cb(data, 0, NULL);
5252 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5254 compose_attach_cb(data, 0, NULL);
5257 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5259 Compose *compose = (Compose *)data;
5261 compose_insert_sig(compose);
5264 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5266 Compose *compose = (Compose *)data;
5268 compose_exec_ext_editor(compose);
5271 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5273 Compose *compose = (Compose *)data;
5275 compose_wrap_line(compose);
5278 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5280 compose_address_cb(data, 0, NULL);
5283 static void select_account(Compose * compose, PrefsAccount * ac)
5285 compose->account = ac;
5286 compose_set_title(compose);
5288 #if 0 /* NEW COMPOSE GUI */
5289 if (ac->protocol == A_NNTP) {
5290 GtkItemFactory *ifactory;
5291 GtkWidget *menuitem;
5293 ifactory = gtk_item_factory_from_widget(compose->menubar);
5294 menu_set_sensitive(ifactory,
5295 "/Message/Followup to", TRUE);
5296 gtk_widget_show(compose->newsgroups_hbox);
5297 gtk_widget_show(compose->newsgroups_entry);
5298 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5301 compose->use_to = FALSE;
5302 compose->use_cc = FALSE;
5304 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5305 gtk_check_menu_item_set_active
5306 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5308 menu_set_sensitive(ifactory,
5309 "/Message/To", TRUE);
5310 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5311 gtk_check_menu_item_set_active
5312 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5314 gtk_widget_hide(compose->to_hbox);
5315 gtk_widget_hide(compose->to_entry);
5316 gtk_widget_hide(compose->cc_hbox);
5317 gtk_widget_hide(compose->cc_entry);
5318 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5320 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5324 GtkItemFactory *ifactory;
5325 GtkWidget *menuitem;
5327 ifactory = gtk_item_factory_from_widget(compose->menubar);
5328 menu_set_sensitive(ifactory,
5329 "/Message/Followup to", FALSE);
5330 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5331 gtk_widget_hide(compose->newsgroups_hbox);
5332 gtk_widget_hide(compose->newsgroups_entry);
5333 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5336 compose->use_to = TRUE;
5337 compose->use_cc = TRUE;
5339 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5340 gtk_check_menu_item_set_active
5341 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5342 menu_set_sensitive(ifactory,
5343 "/Message/To", FALSE);
5344 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5345 gtk_check_menu_item_set_active
5346 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5347 gtk_widget_show(compose->to_hbox);
5348 gtk_widget_show(compose->to_entry);
5349 gtk_widget_show(compose->cc_hbox);
5350 gtk_widget_show(compose->cc_entry);
5352 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5354 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5357 gtk_widget_queue_resize(compose->table_vbox);
5361 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5363 Compose *compose = (Compose *)data;
5367 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
5368 g_return_if_fail(ac != NULL);
5370 if (ac != compose->account)
5371 select_account(compose, ac);
5374 static void attach_selected(GtkCList *clist, gint row, gint column,
5375 GdkEvent *event, gpointer data)
5377 Compose *compose = (Compose *)data;
5379 if (event && event->type == GDK_2BUTTON_PRESS)
5380 compose_attach_property(compose);
5383 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5386 Compose *compose = (Compose *)data;
5387 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5392 if (event->button == 3) {
5393 if ((clist->selection && !clist->selection->next) ||
5394 !clist->selection) {
5395 gtk_clist_unselect_all(clist);
5396 if (gtk_clist_get_selection_info(clist,
5399 gtk_clist_select_row(clist, row, column);
5400 gtkut_clist_set_focus_row(clist, row);
5403 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5404 NULL, NULL, event->button, event->time);
5408 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5411 Compose *compose = (Compose *)data;
5415 switch (event->keyval) {
5417 compose_attach_remove_selected(compose);
5422 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
5424 Compose *compose = (Compose *)data;
5427 val = compose_send(compose);
5428 if (val == 0) gtk_widget_destroy(compose->window);
5431 static void compose_send_later_cb(gpointer data, guint action,
5434 Compose *compose = (Compose *)data;
5437 val = compose_queue(compose, NULL, NULL);
5438 if (!val) gtk_widget_destroy(compose->window);
5441 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
5443 Compose *compose = (Compose *)data;
5447 draft = folder_get_default_draft();
5449 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
5450 G_DIR_SEPARATOR, (gint)compose);
5452 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
5457 folder_item_scan(draft);
5458 if (folder_item_add_msg(draft, tmp, TRUE) < 0) {
5465 if (compose->mode == COMPOSE_REEDIT) {
5466 compose_remove_reedit_target(compose);
5467 if (compose->targetinfo &&
5468 compose->targetinfo->folder != draft)
5469 folderview_update_item(compose->targetinfo->folder,
5473 folder_item_scan(draft);
5474 folderview_update_item(draft, TRUE);
5476 gtk_widget_destroy(compose->window);
5479 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
5481 Compose *compose = (Compose *)data;
5484 if (compose->bounce_filename != NULL)
5487 file_list = filesel_select_multiple_files(_("Select file"), NULL);
5492 for ( tmp = file_list; tmp; tmp = tmp->next) {
5493 gchar *file = (gchar *) tmp->data;
5494 compose_attach_append(compose, file, MIME_UNKNOWN);
5497 g_list_free(file_list);
5501 static void compose_insert_file_cb(gpointer data, guint action,
5504 Compose *compose = (Compose *)data;
5507 file_list = filesel_select_multiple_files(_("Select file"), NULL);
5512 for ( tmp = file_list; tmp; tmp = tmp->next) {
5513 gchar *file = (gchar *) tmp->data;
5514 compose_insert_file(compose, file);
5517 g_list_free(file_list);
5521 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
5524 compose_close_cb(data, 0, NULL);
5528 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
5530 Compose *compose = (Compose *)data;
5533 if (compose->exteditor_tag != -1) {
5534 if (!compose_ext_editor_kill(compose))
5538 if (compose->modified) {
5539 val = alertpanel(_("Discard message"),
5540 _("This message has been modified. discard it?"),
5541 _("Discard"), _("to Draft"), _("Cancel"));
5544 case G_ALERTDEFAULT:
5546 case G_ALERTALTERNATE:
5547 compose_draft_cb(data, 0, NULL);
5554 if (compose->gtkpspell) {
5555 gtkpspell_detach(compose->gtkpspell);
5556 compose->gtkpspell = gtkpspell_delete(compose->gtkpspell);
5559 gtk_widget_destroy(compose->window);
5562 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
5564 Compose *compose = (Compose *)data;
5566 addressbook_open(compose);
5569 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
5571 Compose *compose = (Compose *)data;
5574 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
5575 g_return_if_fail(tmpl != NULL);
5577 compose_template_apply(compose, tmpl->value);
5580 static void compose_ext_editor_cb(gpointer data, guint action,
5583 Compose *compose = (Compose *)data;
5585 compose_exec_ext_editor(compose);
5588 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
5590 compose_destroy(compose);
5593 static void compose_cut_cb(Compose *compose)
5595 if (compose->focused_editable &&
5596 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5597 gtk_editable_cut_clipboard
5598 (GTK_EDITABLE(compose->focused_editable));
5601 static void compose_copy_cb(Compose *compose)
5603 if (compose->focused_editable &&
5604 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5605 gtk_editable_copy_clipboard
5606 (GTK_EDITABLE(compose->focused_editable));
5609 static void compose_paste_cb(Compose *compose)
5611 if (compose->focused_editable &&
5612 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5613 gtk_editable_paste_clipboard
5614 (GTK_EDITABLE(compose->focused_editable));
5617 static void compose_allsel_cb(Compose *compose)
5619 if (compose->focused_editable &&
5620 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5621 gtk_editable_select_region
5622 (GTK_EDITABLE(compose->focused_editable), 0, -1);
5625 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
5627 if (GTK_IS_EDITABLE(widget))
5628 compose->focused_editable = widget;
5631 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
5633 if (compose->modified == FALSE) {
5634 compose->modified = TRUE;
5635 compose_set_title(compose);
5639 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
5642 gtk_stext_set_point(GTK_STEXT(widget),
5643 gtk_editable_get_position(GTK_EDITABLE(widget)));
5647 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
5650 gtk_stext_set_point(GTK_STEXT(widget),
5651 gtk_editable_get_position(GTK_EDITABLE(widget)));
5655 #if 0 /* NEW COMPOSE GUI */
5656 static void compose_toggle_to_cb(gpointer data, guint action,
5659 Compose *compose = (Compose *)data;
5661 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5662 gtk_widget_show(compose->to_hbox);
5663 gtk_widget_show(compose->to_entry);
5664 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
5665 compose->use_to = TRUE;
5667 gtk_widget_hide(compose->to_hbox);
5668 gtk_widget_hide(compose->to_entry);
5669 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
5670 gtk_widget_queue_resize(compose->table_vbox);
5671 compose->use_to = FALSE;
5674 if (addressbook_get_target_compose() == compose)
5675 addressbook_set_target_compose(compose);
5678 static void compose_toggle_cc_cb(gpointer data, guint action,
5681 Compose *compose = (Compose *)data;
5683 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5684 gtk_widget_show(compose->cc_hbox);
5685 gtk_widget_show(compose->cc_entry);
5686 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
5687 compose->use_cc = TRUE;
5689 gtk_widget_hide(compose->cc_hbox);
5690 gtk_widget_hide(compose->cc_entry);
5691 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
5692 gtk_widget_queue_resize(compose->table_vbox);
5693 compose->use_cc = FALSE;
5696 if (addressbook_get_target_compose() == compose)
5697 addressbook_set_target_compose(compose);
5700 static void compose_toggle_bcc_cb(gpointer data, guint action,
5703 Compose *compose = (Compose *)data;
5705 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5706 gtk_widget_show(compose->bcc_hbox);
5707 gtk_widget_show(compose->bcc_entry);
5708 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
5709 compose->use_bcc = TRUE;
5711 gtk_widget_hide(compose->bcc_hbox);
5712 gtk_widget_hide(compose->bcc_entry);
5713 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
5714 gtk_widget_queue_resize(compose->table_vbox);
5715 compose->use_bcc = FALSE;
5718 if (addressbook_get_target_compose() == compose)
5719 addressbook_set_target_compose(compose);
5722 static void compose_toggle_replyto_cb(gpointer data, guint action,
5725 Compose *compose = (Compose *)data;
5727 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5728 gtk_widget_show(compose->reply_hbox);
5729 gtk_widget_show(compose->reply_entry);
5730 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
5731 compose->use_replyto = TRUE;
5733 gtk_widget_hide(compose->reply_hbox);
5734 gtk_widget_hide(compose->reply_entry);
5735 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
5736 gtk_widget_queue_resize(compose->table_vbox);
5737 compose->use_replyto = FALSE;
5741 static void compose_toggle_followupto_cb(gpointer data, guint action,
5744 Compose *compose = (Compose *)data;
5746 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5747 gtk_widget_show(compose->followup_hbox);
5748 gtk_widget_show(compose->followup_entry);
5749 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
5750 compose->use_followupto = TRUE;
5752 gtk_widget_hide(compose->followup_hbox);
5753 gtk_widget_hide(compose->followup_entry);
5754 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
5755 gtk_widget_queue_resize(compose->table_vbox);
5756 compose->use_followupto = FALSE;
5760 static void compose_toggle_attach_cb(gpointer data, guint action,
5763 Compose *compose = (Compose *)data;
5765 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5766 gtk_widget_ref(compose->edit_vbox);
5768 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
5769 compose->edit_vbox);
5770 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
5771 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
5773 gtk_widget_show(compose->paned);
5775 gtk_widget_unref(compose->edit_vbox);
5776 gtk_widget_unref(compose->paned);
5778 compose->use_attach = TRUE;
5780 gtk_widget_ref(compose->paned);
5781 gtk_widget_ref(compose->edit_vbox);
5783 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
5785 gtk_container_remove(GTK_CONTAINER(compose->paned),
5786 compose->edit_vbox);
5787 gtk_box_pack_start(GTK_BOX(compose->vbox2),
5788 compose->edit_vbox, TRUE, TRUE, 0);
5790 gtk_widget_unref(compose->edit_vbox);
5792 compose->use_attach = FALSE;
5798 static void compose_toggle_sign_cb(gpointer data, guint action,
5801 Compose *compose = (Compose *)data;
5803 if (GTK_CHECK_MENU_ITEM(widget)->active)
5804 compose->use_signing = TRUE;
5806 compose->use_signing = FALSE;
5809 static void compose_toggle_encrypt_cb(gpointer data, guint action,
5812 Compose *compose = (Compose *)data;
5814 if (GTK_CHECK_MENU_ITEM(widget)->active)
5815 compose->use_encryption = TRUE;
5817 compose->use_encryption = FALSE;
5819 #endif /* USE_GPGME */
5821 static void compose_toggle_ruler_cb(gpointer data, guint action,
5824 Compose *compose = (Compose *)data;
5826 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5827 gtk_widget_show(compose->ruler_hbox);
5828 prefs_common.show_ruler = TRUE;
5830 gtk_widget_hide(compose->ruler_hbox);
5831 gtk_widget_queue_resize(compose->edit_vbox);
5832 prefs_common.show_ruler = FALSE;
5836 static void compose_attach_drag_received_cb (GtkWidget *widget,
5837 GdkDragContext *drag_context,
5840 GtkSelectionData *data,
5845 Compose *compose = (Compose *)user_data;
5848 list = uri_list_extract_filenames((const gchar *)data->data);
5849 for (tmp = list; tmp != NULL; tmp = tmp->next)
5850 compose_attach_append(compose, (const gchar *)tmp->data,
5852 list_free_strings(list);
5856 static void compose_insert_drag_received_cb (GtkWidget *widget,
5857 GdkDragContext *drag_context,
5860 GtkSelectionData *data,
5865 Compose *compose = (Compose *)user_data;
5868 list = uri_list_extract_filenames((const gchar *)data->data);
5869 for (tmp = list; tmp != NULL; tmp = tmp->next)
5870 compose_insert_file(compose, (const gchar *)tmp->data);
5871 list_free_strings(list);
5875 #if 0 /* NEW COMPOSE GUI */
5876 static void to_activated(GtkWidget *widget, Compose *compose)
5878 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
5879 gtk_widget_grab_focus(compose->newsgroups_entry);
5881 gtk_widget_grab_focus(compose->subject_entry);
5884 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
5886 gtk_widget_grab_focus(compose->subject_entry);
5889 static void subject_activated(GtkWidget *widget, Compose *compose)
5891 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
5892 gtk_widget_grab_focus(compose->cc_entry);
5893 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
5894 gtk_widget_grab_focus(compose->bcc_entry);
5895 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
5896 gtk_widget_grab_focus(compose->reply_entry);
5897 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
5898 gtk_widget_grab_focus(compose->followup_entry);
5900 gtk_widget_grab_focus(compose->text);
5903 static void cc_activated(GtkWidget *widget, Compose *compose)
5905 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
5906 gtk_widget_grab_focus(compose->bcc_entry);
5907 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
5908 gtk_widget_grab_focus(compose->reply_entry);
5909 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
5910 gtk_widget_grab_focus(compose->followup_entry);
5912 gtk_widget_grab_focus(compose->text);
5915 static void bcc_activated(GtkWidget *widget, Compose *compose)
5917 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
5918 gtk_widget_grab_focus(compose->reply_entry);
5919 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
5920 gtk_widget_grab_focus(compose->followup_entry);
5922 gtk_widget_grab_focus(compose->text);
5925 static void replyto_activated(GtkWidget *widget, Compose *compose)
5927 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
5928 gtk_widget_grab_focus(compose->followup_entry);
5930 gtk_widget_grab_focus(compose->text);
5933 static void followupto_activated(GtkWidget *widget, Compose *compose)
5935 gtk_widget_grab_focus(compose->text);
5939 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
5942 Compose *compose = (Compose *)data;
5944 if (GTK_CHECK_MENU_ITEM(widget)->active)
5945 compose->return_receipt = TRUE;
5947 compose->return_receipt = FALSE;
5950 void compose_headerentry_key_press_event_cb(GtkWidget *entry, GdkEventKey *event, compose_headerentry *headerentry) {
5951 if((g_slist_length(headerentry->compose->header_list) > 0) &&
5952 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
5953 !(event->state & GDK_MODIFIER_MASK) &&
5954 (event->keyval == GDK_BackSpace) &&
5955 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
5956 gtk_container_remove(GTK_CONTAINER(headerentry->compose->header_table), headerentry->combo);
5957 gtk_container_remove(GTK_CONTAINER(headerentry->compose->header_table), headerentry->entry);
5958 headerentry->compose->header_list = g_slist_remove(headerentry->compose->header_list, headerentry);
5959 g_free(headerentry);
5963 void compose_headerentry_changed_cb(GtkWidget *entry, compose_headerentry *headerentry) {
5964 if(strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
5965 headerentry->compose->header_list = g_slist_append(headerentry->compose->header_list, headerentry);
5966 compose_create_header_entry(headerentry->compose);
5967 gtk_signal_disconnect_by_func(GTK_OBJECT(entry), GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);