2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtkmain.h>
29 #include <gtk/gtkmenu.h>
30 #include <gtk/gtkmenuitem.h>
31 #include <gtk/gtkitemfactory.h>
32 #include <gtk/gtkcheckmenuitem.h>
33 #include <gtk/gtkoptionmenu.h>
34 #include <gtk/gtkwidget.h>
35 #include <gtk/gtkclist.h>
36 #include <gtk/gtkctree.h>
37 #include <gtk/gtkvpaned.h>
38 #include <gtk/gtkentry.h>
39 #include <gtk/gtkeditable.h>
40 #include <gtk/gtkwindow.h>
41 #include <gtk/gtksignal.h>
42 #include <gtk/gtkvbox.h>
43 #include <gtk/gtkcontainer.h>
44 #include <gtk/gtkhandlebox.h>
45 #include <gtk/gtktoolbar.h>
46 #include <gtk/gtktable.h>
47 #include <gtk/gtkhbox.h>
48 #include <gtk/gtklabel.h>
49 #include <gtk/gtkscrolledwindow.h>
50 #include <gtk/gtkthemes.h>
51 #include <gtk/gtkdnd.h>
58 /* #include <sys/utsname.h> */
64 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
74 #include "mainwindow.h"
76 #include "addressbook.h"
77 #include "folderview.h"
82 #include "customheader.h"
83 #include "prefs_common.h"
84 #include "prefs_account.h"
87 #include "procheader.h"
89 #include "statusbar.h"
96 #include "alertpanel.h"
97 #include "manage_window.h"
98 #include "gtkshruler.h"
100 #include "addr_compl.h"
101 #include "quote_fmt.h"
102 #include "template.h"
105 # include "rfc2015.h"
115 #define N_ATTACH_COLS 3
117 #define B64_LINE_SIZE 57
118 #define B64_BUFFSIZE 77
120 #define MAX_REFERENCES_LEN 999
122 static GdkColor quote_color = {0, 0, 0, 0xbfff};
124 static GList *compose_list = NULL;
126 Compose *compose_generic_new (PrefsAccount *account,
130 static Compose *compose_create (PrefsAccount *account,
132 static void compose_toolbar_create (Compose *compose,
133 GtkWidget *container);
134 static GtkWidget *compose_account_option_menu_create
136 static void compose_set_template_menu (Compose *compose);
137 static void compose_template_apply (Compose *compose,
139 static void compose_destroy (Compose *compose);
141 static void compose_entries_set (Compose *compose,
142 const gchar *mailto);
143 static gint compose_parse_header (Compose *compose,
145 static gchar *compose_parse_references (const gchar *ref,
148 static gchar *compose_quote_fmt (Compose *compose,
153 static void compose_reply_set_entry (Compose *compose,
158 followup_and_reply_to);
159 static void compose_reedit_set_entry (Compose *compose,
161 static void compose_insert_sig (Compose *compose);
162 static void compose_insert_file (Compose *compose,
164 static void compose_attach_append (Compose *compose,
166 ContentType cnttype);
167 static void compose_attach_append_with_type(Compose *compose,
170 ContentType cnttype);
171 static void compose_wrap_line (Compose *compose);
172 static void compose_wrap_line_all (Compose *compose);
173 static void compose_set_title (Compose *compose);
175 static PrefsAccount *compose_current_mail_account(void);
176 /* static gint compose_send (Compose *compose); */
177 static gint compose_write_to_file (Compose *compose,
180 static gint compose_write_body_to_file (Compose *compose,
182 static gint compose_save_to_outbox (Compose *compose,
184 static gint compose_remove_reedit_target (Compose *compose);
185 static gint compose_queue (Compose *compose,
188 static void compose_write_attach (Compose *compose,
190 static gint compose_write_headers (Compose *compose,
192 const gchar *charset,
193 EncodingType encoding,
196 static void compose_convert_header (gchar *dest,
200 static void compose_generate_msgid (Compose *compose,
204 static void compose_attach_info_free (AttachInfo *ainfo);
205 static void compose_attach_remove_selected (Compose *compose);
207 static void compose_attach_property (Compose *compose);
208 static void compose_attach_property_create (gboolean *cancelled);
209 static void attach_property_ok (GtkWidget *widget,
210 gboolean *cancelled);
211 static void attach_property_cancel (GtkWidget *widget,
212 gboolean *cancelled);
213 static gint attach_property_delete_event (GtkWidget *widget,
215 gboolean *cancelled);
216 static void attach_property_key_pressed (GtkWidget *widget,
218 gboolean *cancelled);
220 static void compose_exec_ext_editor (Compose *compose);
221 static gint compose_exec_ext_editor_real (const gchar *file);
222 static gboolean compose_ext_editor_kill (Compose *compose);
223 static void compose_input_cb (gpointer data,
225 GdkInputCondition condition);
226 static void compose_set_ext_editor_sensitive (Compose *compose,
229 static gint calc_cursor_xpos (GtkSText *text,
233 static void compose_create_header_entry (Compose *compose);
234 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
236 /* callback functions */
238 static gboolean compose_edit_size_alloc (GtkEditable *widget,
239 GtkAllocation *allocation,
240 GtkSHRuler *shruler);
242 static void toolbar_send_cb (GtkWidget *widget,
244 static void toolbar_send_later_cb (GtkWidget *widget,
246 static void toolbar_draft_cb (GtkWidget *widget,
248 static void toolbar_insert_cb (GtkWidget *widget,
250 static void toolbar_attach_cb (GtkWidget *widget,
252 static void toolbar_sig_cb (GtkWidget *widget,
254 static void toolbar_ext_editor_cb (GtkWidget *widget,
256 static void toolbar_linewrap_cb (GtkWidget *widget,
258 static void toolbar_address_cb (GtkWidget *widget,
261 static void select_account (Compose *compose,
264 static void account_activated (GtkMenuItem *menuitem,
267 static void attach_selected (GtkCList *clist,
272 static void attach_button_pressed (GtkWidget *widget,
273 GdkEventButton *event,
275 static void attach_key_pressed (GtkWidget *widget,
279 static void compose_send_cb (gpointer data,
282 static void compose_send_later_cb (gpointer data,
286 static void compose_draft_cb (gpointer data,
290 static void compose_attach_cb (gpointer data,
293 static void compose_insert_file_cb (gpointer data,
297 static void compose_close_cb (gpointer data,
301 static void compose_address_cb (gpointer data,
304 static void compose_template_activate_cb(GtkWidget *widget,
307 static void compose_ext_editor_cb (gpointer data,
311 static gint compose_delete_cb (GtkWidget *widget,
314 static void compose_destroy_cb (GtkWidget *widget,
317 static void compose_cut_cb (Compose *compose);
318 static void compose_copy_cb (Compose *compose);
319 static void compose_paste_cb (Compose *compose);
320 static void compose_allsel_cb (Compose *compose);
322 static void compose_grab_focus_cb (GtkWidget *widget,
325 static void compose_changed_cb (GtkEditable *editable,
327 static void compose_button_press_cb (GtkWidget *widget,
328 GdkEventButton *event,
331 static void compose_key_press_cb (GtkWidget *widget,
337 static void compose_toggle_to_cb (gpointer data,
340 static void compose_toggle_cc_cb (gpointer data,
343 static void compose_toggle_bcc_cb (gpointer data,
346 static void compose_toggle_replyto_cb (gpointer data,
349 static void compose_toggle_followupto_cb(gpointer data,
352 static void compose_toggle_attach_cb (gpointer data,
356 static void compose_toggle_ruler_cb (gpointer data,
360 static void compose_toggle_sign_cb (gpointer data,
363 static void compose_toggle_encrypt_cb (gpointer data,
367 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
370 static void compose_attach_drag_received_cb (GtkWidget *widget,
371 GdkDragContext *drag_context,
374 GtkSelectionData *data,
378 static void compose_insert_drag_received_cb (GtkWidget *widget,
379 GdkDragContext *drag_context,
382 GtkSelectionData *data,
388 static void to_activated (GtkWidget *widget,
390 static void newsgroups_activated (GtkWidget *widget,
392 static void subject_activated (GtkWidget *widget,
394 static void cc_activated (GtkWidget *widget,
396 static void bcc_activated (GtkWidget *widget,
398 static void replyto_activated (GtkWidget *widget,
400 static void followupto_activated (GtkWidget *widget,
404 static void compose_attach_parts (Compose *compose,
407 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
409 gboolean ignore_replyto,
410 gboolean followup_and_reply_to);
412 void compose_headerentry_changed_cb (GtkWidget *entry,
413 ComposeHeaderEntry *headerentry);
414 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
416 ComposeHeaderEntry *headerentry);
418 static GtkItemFactoryEntry compose_popup_entries[] =
420 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
421 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
422 {N_("/---"), NULL, NULL, 0, "<Separator>"},
423 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
426 static GtkItemFactoryEntry compose_entries[] =
428 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
429 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
430 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
431 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
432 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
433 {N_("/_File/_Close"), "<alt>W", compose_close_cb, 0, NULL},
435 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
436 {N_("/_Edit/_Undo"), "<control>Z", NULL, 0, NULL},
437 {N_("/_Edit/_Redo"), "<control>Y", NULL, 0, NULL},
438 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
439 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
440 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
441 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
442 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
443 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
444 {N_("/_Edit/_Wrap current paragraph"), "<alt>L", compose_wrap_line, 0, NULL},
445 {N_("/_Edit/Wrap all long _lines"),
446 "<shift><alt>L", compose_wrap_line_all, 0, NULL},
447 {N_("/_Edit/Edit with e_xternal editor"),
448 "<alt>X", compose_ext_editor_cb, 0, NULL},
450 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
451 {N_("/_Message/_Send"), "<control>Return",
452 compose_send_cb, 0, NULL},
453 {N_("/_Message/Send _later"), "<shift><alt>S",
454 compose_send_later_cb, 0, NULL},
455 {N_("/_Message/Save to _draft folder"),
456 "<alt>D", compose_draft_cb, 0, NULL},
457 #if 0 /* NEW COMPOSE GUI */
458 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
459 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
460 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
461 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
462 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
463 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
464 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
465 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
466 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
469 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
470 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
471 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
472 #endif /* USE_GPGME */
473 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
474 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
475 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
476 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
477 {N_("/_Tool/_Address book"), "<alt>A", compose_address_cb , 0, NULL},
478 {N_("/_Tool/_Template"), NULL, NULL, 0, "<Branch>"},
479 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
480 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
483 static GtkTargetEntry compose_mime_types[] =
485 {"text/uri-list", 0, 0}
488 Compose *compose_new(PrefsAccount *account)
490 return compose_generic_new(account, NULL, NULL);
493 Compose *compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
497 GtkItemFactory *ifactory;
499 c = compose_generic_new(account, NULL, NULL);
501 filename = procmsg_get_message_file(msginfo);
502 if (filename == NULL)
505 c->bounce_filename = filename;
507 if (msginfo->subject)
508 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
510 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
512 compose_quote_fmt(c, msginfo, "%M", NULL);
513 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
515 ifactory = gtk_item_factory_from_widget(c->popupmenu);
516 menu_set_sensitive(ifactory, "/Add...", FALSE);
517 menu_set_sensitive(ifactory, "/Remove", FALSE);
518 menu_set_sensitive(ifactory, "/Property...", FALSE);
520 ifactory = gtk_item_factory_from_widget(c->menubar);
521 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
522 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
523 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
524 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
525 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
526 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
527 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
528 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
530 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
531 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
533 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
534 menu_set_sensitive(ifactory, "/Tool/Template", FALSE);
536 gtk_widget_set_sensitive(c->insert_btn, FALSE);
537 gtk_widget_set_sensitive(c->attach_btn, FALSE);
538 gtk_widget_set_sensitive(c->sig_btn, FALSE);
539 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
540 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
545 Compose *compose_new_with_recipient(PrefsAccount *account, const gchar *mailto)
547 return compose_generic_new(account, mailto, NULL);
550 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
552 return compose_generic_new(account, NULL, item);
555 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item)
559 if (item && item->prefs && item->prefs->enable_default_account)
560 account = account_find_from_id(item->prefs->default_account);
562 if (!account) account = cur_account;
563 g_return_val_if_fail(account != NULL, NULL);
565 compose = compose_create(account, COMPOSE_NEW);
566 compose->replyinfo = NULL;
568 if (prefs_common.auto_sig)
569 compose_insert_sig(compose);
570 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
571 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
573 if (account->protocol != A_NNTP) {
575 compose_entries_set(compose, mailto);
577 } else if(item && item->prefs->enable_default_to) {
578 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
580 if (item && item->ret_rcpt) {
581 GtkItemFactory *ifactory;
583 ifactory = gtk_item_factory_from_widget(compose->menubar);
584 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
588 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
591 gtk_widget_grab_focus(compose->subject_entry);
593 if (prefs_common.auto_exteditor)
594 compose_exec_ext_editor(compose);
599 #define CHANGE_FLAGS(msginfo) \
601 if (msginfo->folder->folder->change_flags != NULL) \
602 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
608 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
609 const gchar *followupto, gchar * to)
613 if (!account) account = cur_account;
614 g_return_val_if_fail(account != NULL, NULL);
615 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
617 compose = compose_create(account, COMPOSE_NEW);
619 if (prefs_common.auto_sig)
620 compose_insert_sig(compose);
621 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
622 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
624 compose_entry_append(compose, to, COMPOSE_TO);
625 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
626 gtk_widget_grab_focus(compose->subject_entry);
632 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
633 gboolean ignore_replyto)
635 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE);
638 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
640 gboolean ignore_replyto)
642 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE);
645 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
647 gboolean ignore_replyto,
648 gboolean followup_and_reply_to)
651 PrefsAccount *account;
652 PrefsAccount *reply_account;
655 g_return_if_fail(msginfo != NULL);
656 g_return_if_fail(msginfo->folder != NULL);
659 /* select the account set in folderitem's property (if enabled) */
660 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
661 account = account_find_from_id(msginfo->folder->prefs->default_account);
663 /* select the account for the whole folder (IMAP / NNTP) */
665 account = msginfo->folder->folder->account;
667 /* select account by to: and cc: header if enabled */
668 if (prefs_common.reply_account_autosel) {
669 if (!account && msginfo->to) {
671 Xstrdup_a(to, msginfo->to, return);
673 account = account_find_from_address(to);
677 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
679 account = account_find_from_address(cc);
684 /* select current account */
685 if (!account) account = cur_account;
686 g_return_if_fail(account != NULL);
688 if (ignore_replyto && account->protocol == A_NNTP &&
689 !followup_and_reply_to) {
691 account_find_from_address(account->address);
693 reply_account = compose_current_mail_account();
697 reply_account = account;
699 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
700 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
702 CHANGE_FLAGS(msginfo);
704 compose = compose_create(account, COMPOSE_REPLY);
705 compose->replyinfo = procmsg_msginfo_copy(msginfo);
707 #if 0 /* NEW COMPOSE GUI */
708 if (followup_and_reply_to) {
709 gtk_widget_show(compose->to_hbox);
710 gtk_widget_show(compose->to_entry);
711 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
712 compose->use_to = TRUE;
715 if (msginfo->folder && msginfo->folder->ret_rcpt) {
716 GtkItemFactory *ifactory;
718 ifactory = gtk_item_factory_from_widget(compose->menubar);
719 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
722 if (compose_parse_header(compose, msginfo) < 0) return;
723 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
724 followup_and_reply_to);
726 text = GTK_STEXT(compose->text);
727 gtk_stext_freeze(text);
733 if (prefs_common.quotemark && *prefs_common.quotemark)
734 qmark = prefs_common.quotemark;
738 quote_str = compose_quote_fmt(compose, msginfo,
739 prefs_common.quotefmt,
743 if (prefs_common.auto_sig)
744 compose_insert_sig(compose);
745 gtk_editable_set_position(GTK_EDITABLE(text), 0);
746 gtk_stext_set_point(text, 0);
748 if (quote && prefs_common.linewrap_quote)
749 compose_wrap_line_all(compose);
751 gtk_stext_thaw(text);
752 gtk_widget_grab_focus(compose->text);
754 if (prefs_common.auto_exteditor)
755 compose_exec_ext_editor(compose);
759 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
764 g_return_val_if_fail(mimeinfo != NULL, NULL);
766 base = mimeinfo->filename ? mimeinfo->filename
767 : mimeinfo->name ? mimeinfo->name : NULL;
769 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
770 filename = g_strdup_printf("%s%smimetmp.%08x.html",
777 base = base ? base : "";
778 base = g_basename(base);
780 filename = g_strdup_printf("%s%smimetmp.%08x",
788 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
794 static gchar *mime_extract_file(gchar *source, MimeInfo *partinfo)
798 if (!partinfo) return NULL;
800 filename = procmime_get_file_name(partinfo);
802 if (procmime_get_part(filename, source, partinfo) < 0)
804 (_("Can't get the part of multipart message."));
809 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
817 gint boundary_len = 0;
819 glong fpos, prev_fpos;
824 g_return_if_fail(msginfo != NULL);
828 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
829 mimeinfo = procmime_scan_mime_header(fp);
830 if (!mimeinfo) break;
832 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
833 rfc2015_is_encrypted(mimeinfo)) {
834 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED);
836 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
837 !msginfo->plaintext_file &&
838 !msginfo->decryption_failed) {
839 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
840 if (msginfo->plaintext_file &&
841 !msginfo->decryption_failed) {
849 #else /* !USE_GPGME */
850 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
851 mimeinfo = procmime_scan_mime_header(fp);
852 #endif /* USE_GPGME */
855 if (!mimeinfo) return;
856 if (mimeinfo->mime_type == MIME_TEXT)
859 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
861 g_return_if_fail(mimeinfo != NULL);
862 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
864 if (mimeinfo->mime_type == MIME_MULTIPART) {
865 g_return_if_fail(mimeinfo->boundary != NULL);
866 g_return_if_fail(mimeinfo->sub == NULL);
868 g_return_if_fail(fp != NULL);
870 boundary = mimeinfo->boundary;
873 boundary_len = strlen(boundary);
875 /* look for first boundary */
876 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
877 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
884 if ((fpos = ftell(fp)) < 0) {
890 for (npart = 0;; npart++) {
892 gboolean eom = FALSE;
896 partinfo = procmime_scan_mime_header(fp);
897 if (!partinfo) break;
900 procmime_mimeinfo_insert(mimeinfo, partinfo);
902 procmime_mimeinfo_free(partinfo);
904 /* look for next boundary */
906 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
907 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
908 if (buf[2 + boundary_len] == '-' &&
909 buf[2 + boundary_len + 1] == '-')
915 eom = TRUE; /* broken MIME message */
918 partinfo->size = fpos - prev_fpos - strlen(buf);
923 source = procmsg_get_message_file_path(msginfo);
925 g_return_if_fail(mimeinfo != NULL);
927 if (!mimeinfo->main && mimeinfo->parent)
929 filename = mime_extract_file(source, mimeinfo);
931 compose_attach_append_with_type(compose, filename,
932 mimeinfo->content_type,
933 mimeinfo->mime_type);
938 if (mimeinfo->sub && mimeinfo->sub->children)
940 filename = mime_extract_file(source, mimeinfo->sub);
942 compose_attach_append_with_type(compose, filename,
943 mimeinfo->content_type,
944 mimeinfo->sub->mime_type);
949 if (mimeinfo->children) {
952 child = mimeinfo->children;
954 filename = mime_extract_file(source, child);
956 compose_attach_append_with_type(compose, filename,
968 procmime_mimeinfo_free_all(mimeinfo);
972 #define INSERT_FW_HEADER(var, hdr) \
973 if (msginfo->var && *msginfo->var) { \
974 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
975 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
976 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
979 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
983 /* PrefsAccount *account; */
986 g_return_val_if_fail(msginfo != NULL, NULL);
987 g_return_val_if_fail(msginfo->folder != NULL, NULL);
989 account = msginfo->folder->folder->account;
990 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
992 Xstrdup_a(to, msginfo->to, return NULL);
994 account = account_find_from_address(to);
997 if(!account && prefs_common.forward_account_autosel) {
999 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1000 extract_address(cc);
1001 account = account_find_from_address(cc);
1005 if (account == NULL) {
1006 account = cur_account;
1008 account = msginfo->folder->folder->account;
1009 if (!account) account = cur_account;
1012 g_return_val_if_fail(account != NULL, NULL);
1014 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1015 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1016 CHANGE_FLAGS(msginfo);
1018 compose = compose_create(account, COMPOSE_FORWARD);
1020 if (msginfo->subject && *msginfo->subject) {
1021 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1022 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1026 text = GTK_STEXT(compose->text);
1027 gtk_stext_freeze(text);
1032 msgfile = procmsg_get_message_file_path(msginfo);
1033 if (!is_file_exist(msgfile))
1034 g_warning(_("%s: file not exist\n"), msgfile);
1036 compose_attach_append(compose, msgfile,
1037 MIME_MESSAGE_RFC822);
1044 if (prefs_common.fw_quotemark && *prefs_common.fw_quotemark)
1045 qmark = prefs_common.fw_quotemark;
1049 quote_str = compose_quote_fmt(compose, msginfo,
1050 prefs_common.fw_quotefmt, qmark);
1051 compose_attach_parts(compose, msginfo);
1054 if (prefs_common.auto_sig)
1055 compose_insert_sig(compose);
1056 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1057 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1059 gtk_stext_thaw(text);
1060 #if 0 /* NEW COMPOSE GUI */
1061 if (account->protocol != A_NNTP)
1062 gtk_widget_grab_focus(compose->to_entry);
1064 gtk_widget_grab_focus(compose->newsgroups_entry);
1066 gtk_widget_grab_focus(compose->header_last->entry);
1068 if (prefs_common.auto_exteditor)
1069 compose_exec_ext_editor(compose);
1074 #undef INSERT_FW_HEADER
1076 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1083 g_return_val_if_fail(msginfo_list != NULL, NULL);
1085 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1086 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1090 if (account == NULL) {
1091 account = cur_account;
1093 account = msginfo->folder->folder->account;
1094 if (!account) account = cur_account;
1097 g_return_val_if_fail(account != NULL, NULL);
1099 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1100 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1101 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1102 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1105 compose = compose_create(account, COMPOSE_FORWARD);
1107 text = GTK_STEXT(compose->text);
1108 gtk_stext_freeze(text);
1110 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1111 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1112 if (!is_file_exist(msgfile))
1113 g_warning(_("%s: file not exist\n"), msgfile);
1115 compose_attach_append(compose, msgfile,
1116 MIME_MESSAGE_RFC822);
1120 if (prefs_common.auto_sig)
1121 compose_insert_sig(compose);
1122 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1123 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1125 gtk_stext_thaw(text);
1126 #if 0 /* NEW COMPOSE GUI */
1127 if (account->protocol != A_NNTP)
1128 gtk_widget_grab_focus(compose->to_entry);
1130 gtk_widget_grab_focus(compose->newsgroups_entry);
1136 void compose_reedit(MsgInfo *msginfo)
1139 PrefsAccount *account;
1142 gchar buf[BUFFSIZE];
1144 g_return_if_fail(msginfo != NULL);
1145 g_return_if_fail(msginfo->folder != NULL);
1147 account = msginfo->folder->folder->account;
1149 if(!account&& prefs_common.reedit_account_autosel) {
1150 gchar from[BUFFSIZE];
1151 if(!get_header_from_msginfo(msginfo,from,sizeof(from),"FROM:")){ /* Found a FROM header */
1152 extract_address(from);
1153 account = account_find_from_address(from);
1156 if (!account) account = cur_account;
1157 g_return_if_fail(account != NULL);
1159 compose = compose_create(account, COMPOSE_REEDIT);
1160 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1162 if (compose_parse_header(compose, msginfo) < 0) return;
1163 compose_reedit_set_entry(compose, msginfo);
1165 text = GTK_STEXT(compose->text);
1166 gtk_stext_freeze(text);
1168 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1169 g_warning(_("Can't get text part\n"));
1171 while (fgets(buf, sizeof(buf), fp) != NULL)
1172 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1175 compose_attach_parts(compose, msginfo);
1177 gtk_stext_thaw(text);
1178 gtk_widget_grab_focus(compose->text);
1180 if (prefs_common.auto_exteditor)
1181 compose_exec_ext_editor(compose);
1184 GList *compose_get_compose_list(void)
1186 return compose_list;
1189 void compose_entry_append(Compose *compose, const gchar *address,
1190 ComposeEntryType type)
1196 if (!address || *address == '\0') return;
1198 #if 0 /* NEW COMPOSE GUI */
1201 entry = GTK_ENTRY(compose->cc_entry);
1204 entry = GTK_ENTRY(compose->bcc_entry);
1206 case COMPOSE_NEWSGROUPS:
1207 entry = GTK_ENTRY(compose->newsgroups_entry);
1211 entry = GTK_ENTRY(compose->to_entry);
1215 text = gtk_entry_get_text(entry);
1217 gtk_entry_append_text(entry, ", ");
1218 gtk_entry_append_text(entry, address);
1226 header = N_("Bcc:");
1228 case COMPOSE_REPLYTO:
1229 header = N_("Reply-To:");
1231 case COMPOSE_NEWSGROUPS:
1232 header = N_("Newsgroups:");
1234 case COMPOSE_FOLLOWUPTO:
1235 header = N_( "Followup-To:");
1242 header = prefs_common.trans_hdr ? gettext(header) : header;
1244 compose_add_header_entry(compose, header, (gchar *)address);
1247 static void compose_entries_set(Compose *compose, const gchar *mailto)
1249 gchar *subject = NULL;
1257 Xstrdup_a(tmp_mailto, mailto, return);
1261 p = strchr(tmp_mailto, '?');
1268 gchar *field, *value;
1285 if (*value == '\0') continue;
1287 if (!g_strcasecmp(field, "subject")) {
1288 Xalloca(subject, strlen(value) + 1, return);
1289 decode_uri(subject, value);
1290 } else if (!g_strcasecmp(field, "cc")) {
1292 } else if (!g_strcasecmp(field, "bcc")) {
1294 } else if (!g_strcasecmp(field, "body")) {
1295 Xalloca(body, strlen(value) + 1, return);
1296 decode_uri(body, value);
1301 compose_entry_append(compose, to, COMPOSE_TO);
1303 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1305 compose_entry_append(compose, cc, COMPOSE_CC);
1307 compose_entry_append(compose, bcc, COMPOSE_BCC);
1309 gtk_stext_insert(GTK_STEXT(compose->text),
1310 NULL, NULL, NULL, body, -1);
1311 gtk_stext_insert(GTK_STEXT(compose->text),
1312 NULL, NULL, NULL, "\n", 1);
1316 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1318 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1319 {"Cc:", NULL, FALSE},
1320 {"References:", NULL, FALSE},
1321 {"Bcc:", NULL, FALSE},
1322 {"Newsgroups:", NULL, FALSE},
1323 {"Followup-To:", NULL, FALSE},
1324 {"X-Mailing-List:", NULL, FALSE},
1325 {"X-BeenThere:", NULL, FALSE},
1326 {NULL, NULL, FALSE}};
1336 H_X_MAILING_LIST = 6,
1342 g_return_val_if_fail(msginfo != NULL, -1);
1344 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1345 procheader_get_header_fields(fp, hentry);
1348 if (hentry[H_REPLY_TO].body != NULL) {
1349 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1350 compose->replyto = hentry[H_REPLY_TO].body;
1351 hentry[H_REPLY_TO].body = NULL;
1353 if (hentry[H_CC].body != NULL) {
1354 conv_unmime_header_overwrite(hentry[H_CC].body);
1355 compose->cc = hentry[H_CC].body;
1356 hentry[H_CC].body = NULL;
1358 if (hentry[H_X_MAILING_LIST].body != NULL) {
1359 /* this is good enough to parse debian-devel */
1360 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1361 g_return_val_if_fail(buf != NULL, -1 );
1362 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1363 compose->mailinglist = g_strdup(buf);
1365 g_free(hentry[H_X_MAILING_LIST].body);
1366 hentry[H_X_MAILING_LIST].body = NULL ;
1368 if (hentry[H_X_BEENTHERE].body != NULL) {
1369 /* this is good enough to parse the sylpheed-claws lists */
1370 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1371 g_return_val_if_fail(buf != NULL, -1 );
1372 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1373 compose->mailinglist = g_strdup(buf);
1375 g_free(hentry[H_X_BEENTHERE].body);
1376 hentry[H_X_BEENTHERE].body = NULL ;
1378 if (hentry[H_REFERENCES].body != NULL) {
1379 if (compose->mode == COMPOSE_REEDIT)
1380 compose->references = hentry[H_REFERENCES].body;
1382 compose->references = compose_parse_references
1383 (hentry[H_REFERENCES].body, msginfo->msgid);
1384 g_free(hentry[H_REFERENCES].body);
1386 hentry[H_REFERENCES].body = NULL;
1388 if (hentry[H_BCC].body != NULL) {
1389 if (compose->mode == COMPOSE_REEDIT) {
1390 conv_unmime_header_overwrite(hentry[H_BCC].body);
1391 compose->bcc = hentry[H_BCC].body;
1393 g_free(hentry[H_BCC].body);
1394 hentry[H_BCC].body = NULL;
1396 if (hentry[H_NEWSGROUPS].body != NULL) {
1397 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1398 hentry[H_NEWSGROUPS].body = NULL;
1400 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1401 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1402 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1403 hentry[H_FOLLOWUP_TO].body = NULL;
1406 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1407 compose->inreplyto = g_strdup(msginfo->inreplyto);
1408 else if (compose->mode != COMPOSE_REEDIT &&
1409 msginfo->msgid && *msginfo->msgid) {
1410 compose->inreplyto = g_strdup(msginfo->msgid);
1412 if (!compose->references) {
1413 if (msginfo->inreplyto && *msginfo->inreplyto)
1414 compose->references =
1415 g_strdup_printf("<%s>\n\t<%s>",
1419 compose->references =
1420 g_strconcat("<", msginfo->msgid, ">",
1428 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1430 GSList *ref_id_list, *cur;
1434 ref_id_list = references_list_append(NULL, ref);
1435 if (!ref_id_list) return NULL;
1436 if (msgid && *msgid)
1437 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1442 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1443 /* "<" + Message-ID + ">" + CR+LF+TAB */
1444 len += strlen((gchar *)cur->data) + 5;
1446 if (len > MAX_REFERENCES_LEN) {
1447 /* remove second message-ID */
1448 if (ref_id_list && ref_id_list->next &&
1449 ref_id_list->next->next) {
1450 g_free(ref_id_list->next->data);
1451 ref_id_list = g_slist_remove
1452 (ref_id_list, ref_id_list->next->data);
1454 slist_free_strings(ref_id_list);
1455 g_slist_free(ref_id_list);
1462 new_ref = g_string_new("");
1463 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1464 if (new_ref->len > 0)
1465 g_string_append(new_ref, "\n\t");
1466 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1469 slist_free_strings(ref_id_list);
1470 g_slist_free(ref_id_list);
1472 new_ref_str = new_ref->str;
1473 g_string_free(new_ref, FALSE);
1478 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1479 const gchar *fmt, const gchar *qmark)
1481 GtkSText *text = GTK_STEXT(compose->text);
1482 gchar *quote_str = NULL;
1487 if (qmark != NULL) {
1488 quote_fmt_init(msginfo, NULL);
1489 quote_fmt_scan_string(qmark);
1492 buf = quote_fmt_get_buffer();
1494 alertpanel_error(_("Quote mark format error."));
1496 Xstrdup_a(quote_str, buf, return NULL)
1499 quote_fmt_init(msginfo, quote_str);
1500 quote_fmt_scan_string(fmt);
1503 buf = quote_fmt_get_buffer();
1505 alertpanel_error(_("Message reply/forward format error."));
1509 gtk_stext_freeze(text);
1510 gtk_stext_set_point(text, 0);
1511 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
1513 for (p = buf; *p != '\0'; ) {
1514 lastp = strchr(p, '\n');
1515 len = lastp ? lastp - p + 1 : -1;
1516 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1523 gtk_stext_thaw(text);
1528 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1529 gboolean to_all, gboolean ignore_replyto,
1530 gboolean followup_and_reply_to)
1535 GHashTable *to_table;
1537 g_return_if_fail(compose->account != NULL);
1538 g_return_if_fail(msginfo != NULL);
1540 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1541 compose_entry_append(compose,
1542 ((compose->mailinglist && !ignore_replyto)
1543 ? compose->mailinglist
1544 : (compose->replyto && !ignore_replyto)
1546 : msginfo->from ? msginfo->from : ""),
1548 if (compose->account->protocol == A_NNTP) {
1550 compose_entry_append
1551 (compose, msginfo->from ? msginfo->from : "",
1554 compose_entry_append
1556 compose->followup_to ? compose->followup_to
1557 : compose->newsgroups ? compose->newsgroups
1559 COMPOSE_NEWSGROUPS);
1562 if (msginfo->subject && *msginfo->subject) {
1563 gchar *buf, *buf2, *p;
1565 buf = g_strdup(msginfo->subject);
1566 while (!strncasecmp(buf, "Re:", 3)) {
1568 while (isspace(*p)) p++;
1569 memmove(buf, p, strlen(p) + 1);
1572 buf2 = g_strdup_printf("Re: %s", buf);
1573 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1577 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1579 if (!to_all || compose->account->protocol == A_NNTP) return;
1581 from = g_strdup(compose->replyto ? compose->replyto :
1582 msginfo->from ? msginfo->from : "");
1583 extract_address(from);
1585 cc_list = address_list_append(NULL, msginfo->to);
1586 cc_list = address_list_append(cc_list, compose->cc);
1588 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1589 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1590 if (compose->account)
1591 g_hash_table_insert(to_table, compose->account->address,
1592 GINT_TO_POINTER(1));
1594 /* remove address on To: and that of current account */
1595 for (cur = cc_list; cur != NULL; ) {
1596 GSList *next = cur->next;
1598 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1599 cc_list = g_slist_remove(cc_list, cur->data);
1601 g_hash_table_insert(to_table, cur->data, cur);
1605 g_hash_table_destroy(to_table);
1609 for (cur = cc_list; cur != NULL; cur = cur->next)
1610 compose_entry_append(compose, (gchar *)cur->data,
1612 slist_free_strings(cc_list);
1613 g_slist_free(cc_list);
1617 #define SET_ENTRY(entry, str) \
1620 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1623 #define SET_ADDRESS(type, str) \
1626 compose_entry_append(compose, str, type); \
1629 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1631 g_return_if_fail(msginfo != NULL);
1633 SET_ENTRY(subject_entry, msginfo->subject);
1634 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1635 SET_ADDRESS(COMPOSE_CC, compose->cc);
1636 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1637 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1639 #if 0 /* NEW COMPOSE GUI */
1641 GtkItemFactory *ifactory;
1642 GtkWidget *menuitem;
1644 ifactory = gtk_item_factory_from_widget(compose->menubar);
1645 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1646 gtk_check_menu_item_set_active
1647 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1649 if (compose->replyto) {
1650 GtkItemFactory *ifactory;
1651 GtkWidget *menuitem;
1653 ifactory = gtk_item_factory_from_widget(compose->menubar);
1654 menuitem = gtk_item_factory_get_item
1655 (ifactory, "/Message/Reply to");
1656 gtk_check_menu_item_set_active
1657 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1665 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1672 size_t buf_len = 128;
1674 if (strlen(sigfile) < 2)
1677 sigprg = popen(sigfile+1, "r");
1680 buf = g_malloc(buf_len);
1683 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1684 "Unable to insert signature (malloc failed)\n", -1);
1690 while (!feof(sigprg)) {
1691 bzero(buf, buf_len);
1692 fread(buf, buf_len-1, 1, sigprg);
1693 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1701 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1702 "Can't exec file: ", -1);
1703 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1708 static void compose_insert_sig(Compose *compose)
1712 if (compose->account && compose->account->sig_path)
1713 sigfile = g_strdup(compose->account->sig_path);
1715 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1716 DEFAULT_SIGNATURE, NULL);
1719 if (!is_file_or_fifo_exist(sigfile) & (sigfile[0] != '|')) {
1724 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1725 if (prefs_common.sig_sep) {
1726 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1727 prefs_common.sig_sep, -1);
1728 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1732 if (sigfile[0] == '|')
1734 compose_exec_sig(compose, sigfile);
1738 compose_insert_file(compose, sigfile);
1743 static void compose_insert_file(Compose *compose, const gchar *file)
1745 GtkSText *text = GTK_STEXT(compose->text);
1746 gchar buf[BUFFSIZE];
1750 g_return_if_fail(file != NULL);
1752 if ((fp = fopen(file, "r")) == NULL) {
1753 FILE_OP_ERROR(file, "fopen");
1757 gtk_stext_freeze(text);
1759 while (fgets(buf, sizeof(buf), fp) != NULL) {
1760 /* Strip <CR> if DOS/Windoze file, replace <CR> with <LF> if MAC file */
1762 if (len > 1 && buf[len - 2] == '\r' && buf[len - 1] == '\n') {
1763 buf[len - 2] = '\n';
1764 buf[len - 1] = '\0';
1767 if (buf[len] == '\r')
1771 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1774 gtk_stext_thaw(text);
1779 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
1780 ContentType cnttype)
1782 gchar *text[N_ATTACH_COLS];
1785 text[COL_MIMETYPE] = ainfo->content_type;
1786 text[COL_SIZE] = to_human_readable(ainfo->size);
1787 text[COL_NAME] = ainfo->name;
1789 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1790 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1792 if (cnttype != MIME_MESSAGE_RFC822)
1793 compose_changed_cb(NULL, compose);
1796 static void compose_attach_append_with_type(Compose *compose,
1799 ContentType cnttype)
1804 if (!is_file_exist(file)) {
1805 g_warning(_("File %s doesn't exist\n"), file);
1808 if ((size = get_file_size(file)) < 0) {
1809 g_warning(_("Can't get file size of %s\n"), file);
1813 alertpanel_notice(_("File %s is empty\n"), file);
1816 #if 0 /* NEW COMPOSE GUI */
1817 if (!compose->use_attach) {
1818 GtkItemFactory *ifactory;
1819 GtkWidget *menuitem;
1821 ifactory = gtk_item_factory_from_widget(compose->menubar);
1822 menuitem = gtk_item_factory_get_item(ifactory,
1824 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1828 ainfo = g_new0(AttachInfo, 1);
1829 ainfo->file = g_strdup(file);
1831 if (cnttype == MIME_MESSAGE_RFC822) {
1832 ainfo->encoding = ENC_7BIT;
1833 ainfo->name = g_strdup_printf(_("Message: %s"),
1836 ainfo->encoding = ENC_BASE64;
1837 ainfo->name = g_strdup(g_basename(file));
1840 ainfo->content_type = g_strdup(type);
1843 compose_attach_info(compose, ainfo, cnttype);
1846 static void compose_attach_append(Compose *compose, const gchar *file,
1847 ContentType cnttype)
1850 gchar *text[N_ATTACH_COLS];
1854 if (!is_file_exist(file)) {
1855 g_warning(_("File %s doesn't exist\n"), file);
1858 if ((size = get_file_size(file)) < 0) {
1859 g_warning(_("Can't get file size of %s\n"), file);
1863 alertpanel_notice(_("File %s is empty\n"), file);
1866 #if 0 /* NEW COMPOSE GUI */
1867 if (!compose->use_attach) {
1868 GtkItemFactory *ifactory;
1869 GtkWidget *menuitem;
1871 ifactory = gtk_item_factory_from_widget(compose->menubar);
1872 menuitem = gtk_item_factory_get_item(ifactory,
1874 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1878 ainfo = g_new0(AttachInfo, 1);
1879 ainfo->file = g_strdup(file);
1881 if (cnttype == MIME_MESSAGE_RFC822) {
1882 ainfo->content_type = g_strdup("message/rfc822");
1883 ainfo->encoding = ENC_7BIT;
1884 ainfo->name = g_strdup_printf(_("Message: %s"),
1887 ainfo->content_type = procmime_get_mime_type(file);
1888 if (!ainfo->content_type)
1889 ainfo->content_type =
1890 g_strdup("application/octet-stream");
1891 ainfo->encoding = ENC_BASE64;
1892 ainfo->name = g_strdup(g_basename(file));
1896 compose_attach_info(compose, ainfo, cnttype);
1899 static void compose_wrap_line(Compose *compose)
1901 GtkSText *text = GTK_STEXT(compose->text);
1902 gint ch_len, last_ch_len;
1903 gchar cbuf[MB_LEN_MAX], last_ch;
1907 gint p_start, p_end;
1908 gint line_pos, cur_pos;
1909 gint line_len, cur_len;
1911 #define GET_STEXT(pos) \
1912 if (text->use_wchar) \
1913 ch_len = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
1915 cbuf[0] = GTK_STEXT_INDEX(text, (pos)); \
1919 gtk_stext_freeze(text);
1921 text_len = gtk_stext_get_length(text);
1923 /* check to see if the point is on the paragraph mark (empty line). */
1924 cur_pos = gtk_stext_get_point(text);
1926 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
1928 goto compose_end; /* on the paragraph mark */
1929 GET_STEXT(cur_pos - 1);
1930 if (ch_len == 1 && *cbuf == '\n')
1931 goto compose_end; /* on the paragraph mark */
1934 /* find paragraph start. */
1935 line_end = quoted = 0;
1936 for (p_start = cur_pos; p_start >= 0; --p_start) {
1938 if (ch_len == 1 && *cbuf == '\n') {
1940 goto compose_end; /* quoted part */
1947 if (ch_len == 1 && strchr(">:#", *cbuf))
1949 else if (ch_len != 1 || !isspace(*cbuf))
1958 /* find paragraph end. */
1960 for (p_end = cur_pos; p_end < text_len; p_end++) {
1962 if (ch_len == 1 && *cbuf == '\n') {
1969 if (line_end && ch_len == 1 && strchr(">:#", *cbuf))
1970 goto compose_end; /* quoted part */
1975 if (p_end >= text_len)
1978 if (p_start >= p_end)
1981 line_len = cur_len = 0;
1985 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
1995 if (ch_len == 1 && isspace(*cbuf))
1998 if (ch_len == 1 && *cbuf == '\n') {
2000 if (last_ch_len == 1 && !isspace(last_ch)) {
2001 if (cur_pos + 1 < p_end) {
2002 GET_STEXT(cur_pos + 1);
2003 if (ch_len == 1 && !isspace(*cbuf))
2007 gtk_stext_set_point(text, cur_pos + 1);
2008 gtk_stext_backward_delete(text, 1);
2010 gtk_stext_set_point(text, cur_pos);
2011 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2021 last_ch_len = ch_len;
2025 line_pos = cur_pos + 1;
2026 line_len = cur_len + ch_len;
2029 if (cur_len + ch_len > prefs_common.linewrap_len &&
2033 GET_STEXT(line_pos - 1);
2034 if (ch_len == 1 && isspace(*cbuf)) {
2035 gtk_stext_set_point(text, line_pos);
2036 gtk_stext_backward_delete(text, 1);
2045 gtk_stext_set_point(text, line_pos);
2046 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2050 cur_len = cur_len - line_len + ch_len;
2056 line_pos = cur_pos + 1;
2057 line_len = cur_len + ch_len;
2063 gtk_stext_thaw(text);
2068 /* return indent length */
2069 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2071 gint indent_len = 0;
2073 gchar cbuf[MB_LEN_MAX];
2075 for (i = start_pos; i < text_len; i++) {
2076 if (text->use_wchar)
2078 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, i));
2080 cbuf[0] = GTK_STEXT_INDEX(text, i);
2085 /* allow space, tab, > or | */
2086 if (cbuf[0] != ' ' && cbuf[0] != '\t' &&
2087 cbuf[0] != '>' && cbuf[0] != '|')
2095 /* insert quotation string when line was wrapped */
2096 static guint ins_quote(GtkSText *text, guint quote_len, guint indent_len,
2097 guint prev_line_pos, guint text_len,
2104 for (i = 0; i < indent_len; i++) {
2105 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2106 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2108 ins_len = indent_len;
2111 gtk_stext_insert(text, NULL, NULL, NULL, quote_fmt, quote_len);
2112 ins_len = quote_len;
2120 /* Darko: used when I debug wrapping */
2121 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2126 printf("%d [", pos);
2127 for (i = pos; i < tlen; i++) {
2128 ch = GTK_STEXT_INDEX(text, i);
2129 if (breakoncr && ch == '\n')
2137 static void compose_wrap_line_all(Compose *compose)
2139 GtkSText *text = GTK_STEXT(compose->text);
2141 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2142 gint line_len = 0, cur_len = 0;
2144 gint is_new_line = 1, do_delete = 0;
2145 guint qlen = 0, i_len = 0;
2146 guint linewrap_quote = prefs_common.linewrap_quote;
2147 guint linewrap_len = prefs_common.linewrap_len;
2148 gchar *qfmt = prefs_common.quotemark;
2149 gchar cbuf[MB_LEN_MAX];
2151 gtk_stext_freeze(text);
2153 /* make text buffer contiguous */
2154 /* gtk_stext_compact_buffer(text); */
2156 tlen = gtk_stext_get_length(text);
2158 for (; cur_pos < tlen; cur_pos++) {
2159 /* mark position of new line - needed for quotation wrap */
2160 if (linewrap_quote && is_new_line) {
2161 qlen = gtkut_text_str_compare
2162 (text, cur_pos, tlen, qfmt);
2165 i_len = get_indent_length(text, cur_pos, tlen);
2170 printf("new line i_len=%d qlen=%d p_pos=", i_len, qlen);
2171 dump_text(text, p_pos, tlen, 1);
2175 /* get character(s) at current position */
2176 if (text->use_wchar)
2178 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
2180 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
2184 /* fix line length for tabs */
2185 if (ch_len == 1 && *cbuf == '\t') {
2186 guint tab_width = text->default_tab_width;
2187 guint tab_offset = line_len % tab_width;
2190 printf("found tab at pos=%d line_len=%d ", cur_pos,
2194 line_len += tab_width - tab_offset - 1;
2198 printf("new_len=%d\n", line_len);
2202 /* we have encountered line break */
2203 if (ch_len == 1 && *cbuf == '\n') {
2206 gchar cb[MB_CUR_MAX];
2209 printf("found CR at %d\n", cur_pos);
2211 /* if it's just quotation + newline skip it */
2212 if (i_len && (cur_pos + 1 < tlen)) {
2213 /* check if text at new line matches indent */
2214 ilen = gtkut_text_str_compare_n
2215 (text, cur_pos + 1, p_pos, i_len, tlen);
2216 if (cur_pos + ilen < tlen) {
2217 if (text->use_wchar)
2218 clen = wctomb(cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos + ilen + 1));
2220 cb[0] = GTK_STEXT_INDEX(text,
2221 cur_pos + ilen + 1);
2224 /* no need to join the lines */
2225 if ((clen == 1) && (cb[0] == '\n'))
2231 printf("qlen=%d l_len=%d wrap_len=%d do_del=%d\n",
2232 qlen, line_len, linewrap_len, do_delete);
2234 /* should we delete to perform smart wrapping */
2235 if (qlen && line_len < linewrap_len && do_delete) {
2236 /* get rid of newline */
2237 gtk_stext_set_point(text, cur_pos);
2238 gtk_stext_forward_delete(text, 1);
2241 /* if text starts with quote fmt or with
2242 indent string, delete them */
2244 ilen = gtkut_text_str_compare_n
2245 (text, cur_pos, p_pos, i_len,
2248 gtk_stext_forward_delete(text,
2253 if (gtkut_text_str_compare
2254 (text, cur_pos, tlen, qfmt)) {
2255 gtk_stext_forward_delete
2261 if (text->use_wchar)
2263 (cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
2265 cb[0] = GTK_STEXT_INDEX(text, cur_pos);
2269 /* insert space if it's alphanumeric */
2270 if ((cur_pos != line_pos) &&
2271 ((clen > 1) || isalnum(cb[0]))) {
2272 gtk_stext_insert(text, NULL, NULL,
2274 /* gtk_text_compact_buffer(text); */
2278 /* and start over with current line */
2279 cur_pos = p_pos - 1;
2281 line_len = cur_len = 0;
2286 printf("after delete l_pos=");
2287 dump_text(text, line_pos, tlen, 1);
2292 /* mark new line beginning */
2293 line_pos = cur_pos + 1;
2294 line_len = cur_len = 0;
2306 /* possible line break */
2307 if (ch_len == 1 && isspace(*cbuf)) {
2308 line_pos = cur_pos + 1;
2309 line_len = cur_len + ch_len;
2312 /* are we over wrapping length set in preferences ? */
2313 if (cur_len + ch_len > linewrap_len) {
2317 printf("should wrap cur_pos=%d ", cur_pos);
2318 dump_text(text, p_pos, tlen, 1);
2319 dump_text(text, line_pos, tlen, 1);
2321 /* force wrapping if it is one long word but not URL */
2322 if (p_pos + i_len == line_pos)
2323 if (!gtkut_text_is_uri_string
2324 (text, line_pos, tlen))
2325 line_pos = cur_pos - 1;
2327 printf("new line_pos=%d\n", line_pos);
2330 /* if next character is space delete it */
2331 if (text->use_wchar)
2332 clen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
2334 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
2337 if (clen == 1 && isspace(*cbuf)) {
2338 if (p_pos + i_len != line_pos ||
2339 !gtkut_text_is_uri_string
2340 (text, line_pos, tlen)) {
2341 gtk_stext_set_point(text, line_pos);
2342 gtk_stext_backward_delete(text, 1);
2351 /* if it is URL at beginning of line don't wrap */
2352 if (p_pos + i_len == line_pos &&
2353 gtkut_text_is_uri_string(text, line_pos, tlen)) {
2355 printf("found URL at ");
2356 dump_text(text, line_pos, tlen, 1);
2362 gtk_stext_set_point(text, line_pos);
2363 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2364 /* gtk_stext_compact_buffer(text); */
2368 cur_len = cur_len - line_len + ch_len;
2371 printf("after CR insert ");
2372 dump_text(text, line_pos, tlen, 1);
2375 /* should we insert quotation ? */
2376 if (linewrap_quote && qlen) {
2377 /* only if line is not already quoted */
2378 if (!gtkut_text_str_compare
2379 (text, line_pos, tlen, qfmt)) {
2382 if (line_pos - p_pos > i_len) {
2387 /* gtk_stext_compact_buffer(text); */
2391 /* for loop will increase it */
2392 cur_pos = line_pos - 1;
2395 /* start over with current line */
2399 printf("after quote insert ");
2400 dump_text(text, line_pos, tlen, 1);
2408 line_pos = cur_pos + 1;
2409 line_len = cur_len + ch_len;
2411 /* advance to next character in buffer */
2415 gtk_stext_thaw(text);
2419 static void compose_wrap_line_all(Compose *compose)
2421 GtkText *text = GTK_STEXT(compose->text);
2423 guint line_pos = 0, cur_pos = 0;
2424 gint line_len = 0, cur_len = 0;
2426 gchar cbuf[MB_LEN_MAX];
2428 gtk_stext_freeze(text);
2430 text_len = gtk_stext_get_length(text);
2432 for (; cur_pos < text_len; cur_pos++) {
2433 if (text->use_wchar)
2435 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
2437 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
2441 if (ch_len == 1 && *cbuf == '\n') {
2442 line_pos = cur_pos + 1;
2443 line_len = cur_len = 0;
2452 if (ch_len == 1 && isspace(*cbuf)) {
2453 line_pos = cur_pos + 1;
2454 line_len = cur_len + ch_len;
2457 if (cur_len + ch_len > prefs_common.linewrap_len &&
2461 if (text->use_wchar)
2462 tlen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
2464 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
2467 if (tlen == 1 && isspace(*cbuf)) {
2468 gtk_stext_set_point(text, line_pos);
2469 gtk_stext_backward_delete(text, 1);
2477 gtk_stext_set_point(text, line_pos);
2478 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2482 cur_len = cur_len - line_len + ch_len;
2488 line_pos = cur_pos + 1;
2489 line_len = cur_len + ch_len;
2494 gtk_stext_thaw(text);
2498 static void compose_set_title(Compose *compose)
2503 edited = compose->modified ? _(" [Edited]") : "";
2504 if (compose->account && compose->account->address)
2505 str = g_strdup_printf(_("%s - Compose message%s"),
2506 compose->account->address, edited);
2508 str = g_strdup_printf(_("Compose message%s"), edited);
2509 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2514 * compose_current_mail_account:
2516 * Find a current mail account (the currently selected account, or the
2517 * default account, if a news account is currently selected). If a
2518 * mail account cannot be found, display an error message.
2520 * Return value: Mail account, or NULL if not found.
2522 static PrefsAccount *
2523 compose_current_mail_account(void)
2527 if (cur_account && cur_account->protocol != A_NNTP)
2530 ac = account_get_default();
2531 if (!ac || ac->protocol == A_NNTP) {
2532 alertpanel_error(_("Account for sending mail is not specified.\n"
2533 "Please select a mail account before sending."));
2540 gboolean compose_check_for_valid_recipient(Compose *compose) {
2541 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2542 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2543 gboolean recipient_found = FALSE;
2547 /* free to and newsgroup list */
2548 slist_free_strings(compose->to_list);
2549 g_slist_free(compose->to_list);
2550 compose->to_list = NULL;
2552 slist_free_strings(compose->newsgroup_list);
2553 g_slist_free(compose->newsgroup_list);
2554 compose->newsgroup_list = NULL;
2556 /* search header entries for to and newsgroup entries */
2557 for(list = compose->header_list; list; list = list->next) {
2560 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
2561 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2563 if(entry[0] != '\0') {
2564 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2565 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2566 compose->to_list = address_list_append(compose->to_list, entry);
2567 recipient_found = TRUE;
2570 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2571 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2572 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2573 recipient_found = TRUE;
2579 return recipient_found;
2582 gint compose_send(Compose *compose)
2588 val = compose_queue(compose, &msgnum, &folder);
2590 alertpanel_error(_("Could not queue message for sending"));
2594 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2596 folder_item_remove_msg(folder, msgnum);
2597 folderview_update_item(folder, TRUE);
2603 #if 0 /* compose restructure */
2604 gint compose_send(Compose *compose)
2606 gchar tmp[MAXPATHLEN + 1];
2608 static gboolean lock = FALSE;
2612 g_return_val_if_fail(compose->account != NULL, -1);
2613 g_return_val_if_fail(compose->orig_account != NULL, -1);
2617 if(!compose_check_for_valid_recipient(compose)) {
2618 alertpanel_error(_("Recipient is not specified."));
2623 /* write to temporary file */
2624 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2625 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2627 if (prefs_common.linewrap_at_send)
2628 compose_wrap_line_all(compose);
2630 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2635 if (!compose->to_list && !compose->newsgroup_list) {
2636 g_warning(_("can't get recipient list."));
2642 if (compose->to_list) {
2645 #if 0 /* NEW COMPOSE GUI */
2646 if (compose->account->protocol != A_NNTP)
2647 ac = compose->account;
2648 else if (compose->orig_account->protocol != A_NNTP)
2649 ac = compose->orig_account;
2650 else if (cur_account && cur_account->protocol != A_NNTP)
2653 ac = compose_current_mail_account();
2661 ac = compose->account;
2663 ok = send_message(tmp, ac, compose->to_list);
2664 statusbar_pop_all();
2667 if (ok == 0 && compose->newsgroup_list) {
2670 if (compose->account->protocol == A_NNTP)
2671 folder = FOLDER(compose->account->folder);
2673 folder = FOLDER(compose->orig_account->folder);
2675 ok = news_post(folder, tmp);
2677 alertpanel_error(_("Error occurred while posting the message to %s ."),
2678 compose->account->nntp_server);
2685 /* queue message if failed to send */
2687 if (prefs_common.queue_msg) {
2692 _("Error occurred while sending the message.\n"
2693 "Put this message into queue folder?"),
2694 _("OK"), _("Cancel"), NULL);
2695 if (G_ALERTDEFAULT == val) {
2696 ok = compose_queue(compose, tmp);
2698 alertpanel_error(_("Can't queue the message."));
2701 alertpanel_error(_("Error occurred while sending the message."));
2703 if (compose->mode == COMPOSE_REEDIT) {
2704 compose_remove_reedit_target(compose);
2705 if (compose->targetinfo)
2706 folderview_update_item
2707 (compose->targetinfo->folder, TRUE);
2711 /* save message to outbox */
2712 if (ok == 0 && prefs_common.savemsg) {
2713 if (compose_save_to_outbox(compose, tmp) < 0)
2715 (_("Can't save the message to outbox."));
2724 static gboolean compose_use_attach(Compose *compose) {
2725 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2728 static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
2731 gchar buf[BUFFSIZE];
2733 gboolean first_address;
2735 ComposeHeaderEntry *headerentry;
2736 gchar *headerentryname;
2737 gchar *header_w_colon;
2741 debug_print(_("Writing bounce header\n"));
2743 header_w_colon = g_strconcat("To:", NULL);
2744 to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2745 header_w_colon = g_strconcat("Cc:", NULL);
2746 cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2748 first_address = TRUE;
2749 for(list = compose->header_list; list; list = list->next) {
2750 headerentry = ((ComposeHeaderEntry *)list->data);
2751 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2753 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2754 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2755 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2756 Xstrdup_a(str, str, return -1);
2758 if(str[0] != '\0') {
2759 compose_convert_header
2760 (buf, sizeof(buf), str,
2761 strlen("Resent-To") + 2);
2763 fprintf(fp, "Resent-To: ");
2764 first_address = FALSE;
2768 fprintf(fp, "%s", buf);
2772 /* if(!first_address) { */
2779 static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
2781 gchar buf[BUFFSIZE];
2783 /* struct utsname utsbuf; */
2785 g_return_val_if_fail(fp != NULL, -1);
2786 g_return_val_if_fail(compose->account != NULL, -1);
2787 g_return_val_if_fail(compose->account->address != NULL, -1);
2790 get_rfc822_date(buf, sizeof(buf));
2791 fprintf(fp, "Resent-Date: %s\n", buf);
2794 if (compose->account->name && *compose->account->name) {
2795 compose_convert_header
2796 (buf, sizeof(buf), compose->account->name,
2798 fprintf(fp, "Resent-From: %s <%s>\n",
2799 buf, compose->account->address);
2801 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2804 compose_bounce_write_headers_from_headerlist(compose, fp);
2806 /* separator between header and body */
2812 static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
2817 gchar buf[BUFFSIZE];
2819 if ((fp = fopen(compose->bounce_filename, "r")) == NULL) {
2820 FILE_OP_ERROR(file, "fopen");
2824 if ((fdest = fopen(file, "a+")) == NULL) {
2825 FILE_OP_ERROR(file, "fopen");
2830 /* chmod for security */
2831 if (change_file_mode_rw(fdest, file) < 0) {
2832 FILE_OP_ERROR(file, "chmod");
2833 g_warning(_("can't change file mode\n"));
2836 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2837 /* should filter returnpath, delivered-to */
2838 if ((g_strncasecmp(buf, "Return-Path:",
2839 strlen("Return-Path:")) == 0)
2840 || (g_strncasecmp(buf, "Delivered-To:",
2841 strlen("Delivered-To:")) == 0))
2843 if (fputs(buf, fdest) == -1)
2845 if (fputs("\n", fdest) == -1)
2849 compose_bounce_write_headers(compose, fdest);
2851 while ((len = fread(buf, sizeof(gchar), BUFFSIZE, fp)) > 0) {
2852 if (fwrite(buf, sizeof(gchar), len, fdest) == -1)
2867 static gint compose_write_to_file(Compose *compose, const gchar *file,
2874 const gchar *out_codeset;
2875 EncodingType encoding;
2877 if ((fp = fopen(file, "a+")) == NULL) {
2878 FILE_OP_ERROR(file, "fopen");
2882 /* chmod for security */
2883 if (change_file_mode_rw(fp, file) < 0) {
2884 FILE_OP_ERROR(file, "chmod");
2885 g_warning(_("can't change file mode\n"));
2888 /* get all composed text */
2889 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2890 len = strlen(chars);
2891 if (is_ascii_str(chars)) {
2892 buf = g_strdup(chars);
2893 out_codeset = CS_US_ASCII;
2894 encoding = ENC_7BIT;
2896 const gchar *src_codeset;
2898 out_codeset = conv_get_outgoing_charset_str();
2899 if (!strcasecmp(out_codeset, CS_US_ASCII))
2900 out_codeset = CS_ISO_8859_1;
2901 encoding = procmime_get_encoding_for_charset(out_codeset);
2903 src_codeset = conv_get_current_charset_str();
2904 /* if current encoding is US-ASCII, set it the same as
2905 outgoing one to prevent code conversion failure */
2906 if (!strcasecmp(src_codeset, CS_US_ASCII))
2907 src_codeset = out_codeset;
2909 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
2910 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
2912 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
2917 alertpanel_error(_("Can't convert the codeset of the message."));
2924 if (compose_write_headers
2925 (compose, fp, out_codeset, encoding, is_draft) < 0) {
2926 g_warning(_("can't write headers\n"));
2933 if (compose_use_attach(compose)) {
2935 /* This prolog message is ignored by mime software and
2936 * because it would make our signing/encryption task
2937 * tougher, we don't emit it in that case */
2938 if (!compose->use_signing && !compose->use_encryption)
2940 fputs("This is a multi-part message in MIME format.\n", fp);
2942 fprintf(fp, "\n--%s\n", compose->boundary);
2943 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
2945 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2946 procmime_get_encoding_str(encoding));
2952 if (encoding == ENC_BASE64) {
2953 gchar outbuf[B64_BUFFSIZE];
2956 for (i = 0; i < len; i += B64_LINE_SIZE) {
2957 l = MIN(B64_LINE_SIZE, len - i);
2958 to64frombits(outbuf, buf + i, l);
2962 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
2963 FILE_OP_ERROR(file, "fwrite");
2971 if (compose_use_attach(compose))
2972 compose_write_attach(compose, fp);
2974 if (fclose(fp) == EOF) {
2975 FILE_OP_ERROR(file, "fclose");
2981 if (compose->use_signing) {
2982 if (rfc2015_sign(file, compose->account) < 0) {
2987 if (compose->use_encryption) {
2988 if (rfc2015_encrypt(file, compose->to_list) < 0) {
2993 #endif /* USE_GPGME */
2998 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3004 if ((fp = fopen(file, "w")) == NULL) {
3005 FILE_OP_ERROR(file, "fopen");
3009 /* chmod for security */
3010 if (change_file_mode_rw(fp, file) < 0) {
3011 FILE_OP_ERROR(file, "chmod");
3012 g_warning(_("can't change file mode\n"));
3015 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3018 len = strlen(chars);
3019 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3020 FILE_OP_ERROR(file, "fwrite");
3029 if (fclose(fp) == EOF) {
3030 FILE_OP_ERROR(file, "fclose");
3037 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
3044 debug_print(_("saving sent message...\n"));
3046 outbox = folder_get_default_outbox();
3047 path = folder_item_get_path(outbox);
3048 if (!is_dir_exist(path))
3049 make_dir_hier(path);
3051 folder_item_scan(outbox);
3052 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
3054 g_warning(_("can't save message\n"));
3058 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
3059 g_warning(_("can't open mark file\n"));
3063 newmsginfo.msgnum = num;
3064 newmsginfo.flags.perm_flags = 0;
3065 newmsginfo.flags.tmp_flags = 0;
3066 procmsg_write_flags(&newmsginfo, fp);
3074 static gint compose_remove_reedit_target(Compose *compose)
3077 MsgInfo *msginfo = compose->targetinfo;
3079 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3080 if (!msginfo) return -1;
3082 item = msginfo->folder;
3083 g_return_val_if_fail(item != NULL, -1);
3085 folder_item_scan(item);
3086 if (procmsg_msg_exist(msginfo) &&
3087 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3088 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3089 g_warning(_("can't remove the old message\n"));
3098 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3101 gchar *tmpfilename, *queue_path;
3104 gchar buf[BUFFSIZE];
3106 static gboolean lock = FALSE;
3107 PrefsAccount *mailac = NULL, *newsac = NULL;
3109 debug_print(_("queueing message...\n"));
3110 g_return_val_if_fail(compose->account != NULL, -1);
3111 g_return_val_if_fail(compose->orig_account != NULL, -1);
3115 if(!compose_check_for_valid_recipient(compose)) {
3116 alertpanel_error(_("Recipient is not specified."));
3121 if (!compose->to_list && !compose->newsgroup_list) {
3122 g_warning(_("can't get recipient list."));
3127 if (prefs_common.linewrap_at_send)
3128 compose_wrap_line_all(compose);
3130 /* write to temporary file */
3131 tmpfilename = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3132 G_DIR_SEPARATOR, (gint)compose);
3133 if ((fp = fopen(tmpfilename, "w")) == NULL) {
3134 FILE_OP_ERROR(tmpfilename, "fopen");
3135 g_free(tmpfilename);
3138 if (change_file_mode_rw(fp, tmpfilename) < 0) {
3139 FILE_OP_ERROR(tmpfilename, "chmod");
3140 g_warning(_("can't change file mode\n"));
3143 if(compose->to_list) {
3144 if (compose->account->protocol != A_NNTP)
3145 mailac = compose->account;
3146 else if (compose->orig_account->protocol != A_NNTP)
3147 mailac = compose->orig_account;
3148 else if (cur_account && cur_account->protocol != A_NNTP)
3149 mailac = cur_account;
3150 else if (!(mailac = compose_current_mail_account())) {
3151 unlink(tmpfilename);
3153 alertpanel_error(_("No account for sending mails available!"));
3158 if(compose->newsgroup_list) {
3159 if (compose->account->protocol == A_NNTP)
3160 newsac = compose->account;
3161 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3162 unlink(tmpfilename);
3164 alertpanel_error(_("No account for posting news available!"));
3169 /* queueing variables */
3170 fprintf(fp, "AF:\n");
3171 fprintf(fp, "NF:0\n");
3172 fprintf(fp, "PS:10\n");
3173 fprintf(fp, "SRH:1\n");
3174 fprintf(fp, "SFN:\n");
3175 fprintf(fp, "DSR:\n");
3177 fprintf(fp, "MID:<%s>\n", compose->msgid);
3179 fprintf(fp, "MID:\n");
3180 fprintf(fp, "CFG:\n");
3181 fprintf(fp, "PT:0\n");
3182 fprintf(fp, "S:%s\n", compose->account->address);
3183 fprintf(fp, "RQ:\n");
3185 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3187 fprintf(fp, "SSV:\n");
3189 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3191 fprintf(fp, "NSV:\n");
3192 fprintf(fp, "SSH:\n");
3193 /* write recepient list */
3195 if(compose->to_list) {
3196 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3197 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3198 fprintf(fp, ",<%s>", (gchar *)cur->data);
3201 /* write newsgroup list */
3203 if(compose->newsgroup_list) {
3204 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3205 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3206 fprintf(fp, ",%s", (gchar *)cur->data);
3209 /* Sylpheed account IDs */
3211 fprintf(fp, "MAID:%d\n", mailac->account_id);
3214 fprintf(fp, "NAID:%d\n", newsac->account_id);
3219 if (compose->bounce_filename != NULL) {
3220 if (compose_bounce_write_to_file(compose, tmpfilename) < 0) {
3221 unlink(tmpfilename);
3227 if (compose_write_to_file(compose, tmpfilename, FALSE) < 0) {
3228 unlink(tmpfilename);
3235 queue = folder_get_default_queue();
3237 folder_item_scan(queue);
3238 queue_path = folder_item_get_path(queue);
3239 if (!is_dir_exist(queue_path))
3240 make_dir_hier(queue_path);
3241 if ((num = folder_item_add_msg(queue, tmpfilename, TRUE)) < 0) {
3242 g_warning(_("can't queue the message\n"));
3243 unlink(tmpfilename);
3244 g_free(tmpfilename);
3248 g_free(tmpfilename);
3250 if (compose->mode == COMPOSE_REEDIT) {
3251 compose_remove_reedit_target(compose);
3252 if (compose->targetinfo &&
3253 compose->targetinfo->folder != queue)
3254 folderview_update_item
3255 (compose->targetinfo->folder, TRUE);
3258 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
3259 g_warning(_("can't open mark file\n"));
3263 newmsginfo.msgnum = num;
3264 newmsginfo.flags.perm_flags = 0;
3265 newmsginfo.flags.tmp_flags = 0;
3266 procmsg_write_flags(&newmsginfo, fp);
3271 folder_item_scan(queue);
3272 folderview_update_item(queue, TRUE);
3274 if((msgnum != NULL) && (item != NULL)) {
3282 static void compose_write_attach(Compose *compose, FILE *fp)
3285 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3288 gchar filename[BUFFSIZE];
3291 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3293 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
3294 g_warning(_("Can't open file %s\n"), ainfo->file);
3298 fprintf(fp, "\n--%s\n", compose->boundary);
3300 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3301 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3302 fprintf(fp, "Content-Disposition: inline\n");
3304 conv_encode_header(filename, sizeof(filename),
3306 fprintf(fp, "Content-Type: %s;\n"
3308 ainfo->content_type, filename);
3309 fprintf(fp, "Content-Disposition: attachment;\n"
3310 " filename=\"%s\"\n", filename);
3313 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3314 procmime_get_encoding_str(ainfo->encoding));
3316 if (ainfo->encoding == ENC_7BIT) {
3317 gchar buf[BUFFSIZE];
3319 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3324 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3326 while ((len = fread(inbuf, sizeof(gchar),
3327 B64_LINE_SIZE, attach_fp))
3329 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3333 if (len > 0 && feof(attach_fp)) {
3334 to64frombits(outbuf, inbuf, len);
3343 fprintf(fp, "\n--%s--\n", compose->boundary);
3346 #define IS_IN_CUSTOM_HEADER(header) \
3347 (compose->account->add_customhdr && \
3348 custom_header_find(compose->account->customhdr_list, header) != NULL)
3350 static gint compose_write_headers_from_headerlist(Compose *compose,
3354 gchar buf[BUFFSIZE];
3355 gchar *str, *header_w_colon, *trans_hdr;
3356 gboolean first_address;
3358 ComposeHeaderEntry *headerentry;
3359 gchar * headerentryname;
3361 if (IS_IN_CUSTOM_HEADER(header)) {
3365 debug_print(_("Writing %s-header\n"), header);
3367 header_w_colon = g_strconcat(header, ":", NULL);
3368 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3370 first_address = TRUE;
3371 for(list = compose->header_list; list; list = list->next) {
3372 headerentry = ((ComposeHeaderEntry *)list->data);
3373 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3375 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3376 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3377 Xstrdup_a(str, str, return -1);
3379 if(str[0] != '\0') {
3380 compose_convert_header
3381 (buf, sizeof(buf), str,
3382 strlen(header) + 2);
3384 fprintf(fp, "%s: ", header);
3385 first_address = FALSE;
3389 fprintf(fp, "%s", buf);
3393 if(!first_address) {
3397 g_free(header_w_colon);
3402 static gint compose_write_headers(Compose *compose, FILE *fp,
3403 const gchar *charset, EncodingType encoding,
3406 gchar buf[BUFFSIZE];
3408 /* struct utsname utsbuf; */
3410 g_return_val_if_fail(fp != NULL, -1);
3411 g_return_val_if_fail(charset != NULL, -1);
3412 g_return_val_if_fail(compose->account != NULL, -1);
3413 g_return_val_if_fail(compose->account->address != NULL, -1);
3416 if (compose->account->add_date) {
3417 get_rfc822_date(buf, sizeof(buf));
3418 fprintf(fp, "Date: %s\n", buf);
3422 if (!IS_IN_CUSTOM_HEADER("From")) {
3423 if (compose->account->name && *compose->account->name) {
3424 compose_convert_header
3425 (buf, sizeof(buf), compose->account->name,
3427 fprintf(fp, "From: %s <%s>\n",
3428 buf, compose->account->address);
3430 fprintf(fp, "From: %s\n", compose->account->address);
3434 compose_write_headers_from_headerlist(compose, fp, "To");
3435 #if 0 /* NEW COMPOSE GUI */
3436 if (compose->use_to) {
3437 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3439 Xstrdup_a(str, str, return -1);
3442 compose->to_list = address_list_append
3443 (compose->to_list, str);
3444 if (!IS_IN_CUSTOM_HEADER("To")) {
3445 compose_convert_header
3446 (buf, sizeof(buf), str,
3448 fprintf(fp, "To: %s\n", buf);
3456 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3457 #if 0 /* NEW COMPOSE GUI */
3458 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3460 Xstrdup_a(str, str, return -1);
3464 compose->newsgroup_list =
3465 newsgroup_list_append(compose->newsgroup_list,
3467 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
3468 compose_convert_header(buf, sizeof(buf), str,
3469 strlen("Newsgroups: "));
3470 fprintf(fp, "Newsgroups: %s\n", buf);
3476 compose_write_headers_from_headerlist(compose, fp, "Cc");
3477 #if 0 /* NEW COMPOSE GUI */
3478 if (compose->use_cc) {
3479 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3481 Xstrdup_a(str, str, return -1);
3484 compose->to_list = address_list_append
3485 (compose->to_list, str);
3486 if (!IS_IN_CUSTOM_HEADER("Cc")) {
3487 compose_convert_header
3488 (buf, sizeof(buf), str,
3490 fprintf(fp, "Cc: %s\n", buf);
3497 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3498 #if 0 /* NEW COMPOSE GUI */
3499 if (compose->use_bcc) {
3500 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3502 Xstrdup_a(str, str, return -1);
3505 compose->to_list = address_list_append
3506 (compose->to_list, str);
3507 compose_convert_header(buf, sizeof(buf), str,
3509 fprintf(fp, "Bcc: %s\n", buf);
3516 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3517 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3518 Xstrdup_a(str, str, return -1);
3521 compose_convert_header(buf, sizeof(buf), str,
3522 strlen("Subject: "));
3523 fprintf(fp, "Subject: %s\n", buf);
3528 if (compose->account->gen_msgid) {
3529 compose_generate_msgid(compose, buf, sizeof(buf));
3530 fprintf(fp, "Message-Id: <%s>\n", buf);
3531 compose->msgid = g_strdup(buf);
3535 if (compose->inreplyto && compose->to_list)
3536 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3539 if (compose->references)
3540 fprintf(fp, "References: %s\n", compose->references);
3543 compose_write_headers_from_headerlist(compose, fp, "Followup-To");
3544 #if 0 /* NEW COMPOSE GUI */
3545 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3546 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3548 Xstrdup_a(str, str, return -1);
3552 compose_convert_header(buf, sizeof(buf), str,
3553 strlen("Followup-To: "));
3554 fprintf(fp, "Followup-To: %s\n", buf);
3560 compose_write_headers_from_headerlist(compose, fp, "Reply-To");
3561 #if 0 /* NEW COMPOSE GUI */
3562 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3563 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3565 Xstrdup_a(str, str, return -1);
3568 compose_convert_header(buf, sizeof(buf), str,
3569 strlen("Reply-To: "));
3570 fprintf(fp, "Reply-To: %s\n", buf);
3576 if (compose->account->organization &&
3577 !IS_IN_CUSTOM_HEADER("Organization")) {
3578 compose_convert_header(buf, sizeof(buf),
3579 compose->account->organization,
3580 strlen("Organization: "));
3581 fprintf(fp, "Organization: %s\n", buf);
3584 /* Program version and system info */
3585 /* uname(&utsbuf); */
3586 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3587 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3589 gtk_major_version, gtk_minor_version, gtk_micro_version,
3591 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3593 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3594 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3596 gtk_major_version, gtk_minor_version, gtk_micro_version,
3598 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3601 /* custom headers */
3602 if (compose->account->add_customhdr) {
3605 for (cur = compose->account->customhdr_list; cur != NULL;
3607 CustomHeader *chdr = (CustomHeader *)cur->data;
3609 if (strcasecmp(chdr->name, "Date") != 0 &&
3610 strcasecmp(chdr->name, "From") != 0 &&
3611 strcasecmp(chdr->name, "To") != 0 &&
3612 /* strcasecmp(chdr->name, "Sender") != 0 && */
3613 strcasecmp(chdr->name, "Message-Id") != 0 &&
3614 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3615 strcasecmp(chdr->name, "References") != 0 &&
3616 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3617 strcasecmp(chdr->name, "Content-Type") != 0 &&
3618 strcasecmp(chdr->name, "Content-Transfer-Encoding")
3620 compose_convert_header
3622 chdr->value ? chdr->value : "",
3623 strlen(chdr->name) + 2);
3624 fprintf(fp, "%s: %s\n", chdr->name, buf);
3630 fprintf(fp, "Mime-Version: 1.0\n");
3631 if (compose_use_attach(compose)) {
3632 get_rfc822_date(buf, sizeof(buf));
3633 subst_char(buf, ' ', '_');
3634 subst_char(buf, ',', '_');
3635 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3636 buf, (guint)compose);
3638 "Content-Type: multipart/mixed;\n"
3639 " boundary=\"%s\"\n", compose->boundary);
3641 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3642 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3643 procmime_get_encoding_str(encoding));
3646 /* Request Return Receipt */
3647 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3648 if (compose->return_receipt) {
3649 if (compose->account->name
3650 && *compose->account->name) {
3651 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3652 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3654 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3658 /* separator between header and body */
3664 #undef IS_IN_CUSTOM_HEADER
3666 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3669 g_return_if_fail(src != NULL);
3670 g_return_if_fail(dest != NULL);
3672 if (len < 1) return;
3676 if (is_ascii_str(src)) {
3677 strncpy2(dest, src, len);
3678 dest[len - 1] = '\0';
3681 conv_encode_header(dest, len, src, header_len);
3684 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3693 if (compose->account && compose->account->address &&
3694 *compose->account->address) {
3695 if (strchr(compose->account->address, '@'))
3696 addr = g_strdup(compose->account->address);
3698 addr = g_strconcat(compose->account->address, "@",
3699 get_domain_name(), NULL);
3701 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3704 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3705 lt->tm_year + 1900, lt->tm_mon + 1,
3706 lt->tm_mday, lt->tm_hour,
3707 lt->tm_min, lt->tm_sec,
3708 (guint)random(), addr);
3710 debug_print(_("generated Message-ID: %s\n"), buf);
3716 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3717 GtkWidget **entry, gint *count,
3718 const gchar *label_str,
3719 gboolean is_addr_entry)
3723 if (GTK_TABLE(table)->nrows < (*count) + 1)
3724 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3726 *hbox = gtk_hbox_new(FALSE, 0);
3727 label = gtk_label_new
3728 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3729 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3730 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3732 *entry = gtk_entry_new_with_max_length(MAX_ENTRY_LENGTH);
3734 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3735 #if 0 /* NEW COMPOSE GUI */
3736 if (GTK_TABLE(table)->nrows > (*count) + 1)
3737 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
3741 address_completion_register_entry(GTK_ENTRY(*entry));
3746 static void compose_create_header_entry(Compose *compose) {
3747 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3751 GList *combo_list = NULL;
3752 gchar **string, *header;
3753 ComposeHeaderEntry *headerentry;
3755 headerentry = g_new0(ComposeHeaderEntry, 1);
3758 combo = gtk_combo_new();
3760 while(*string != NULL) {
3761 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
3764 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
3765 g_list_free(combo_list);
3766 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
3767 gtk_widget_show(combo);
3768 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
3769 if(compose->header_last) {
3770 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
3772 switch(compose->account->protocol) {
3774 header = _("Newsgroups:");
3781 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
3784 entry = gtk_entry_new();
3785 gtk_widget_show(entry);
3786 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);
3788 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
3789 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
3791 address_completion_register_entry(GTK_ENTRY(entry));
3793 headerentry->compose = compose;
3794 headerentry->combo = combo;
3795 headerentry->entry = entry;
3796 headerentry->headernum = compose->header_nextrow;
3798 compose->header_nextrow++;
3799 compose->header_last = headerentry;
3802 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text) {
3803 ComposeHeaderEntry *last_header;
3805 last_header = compose->header_last;
3807 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
3808 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
3811 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
3817 GtkWidget *handlebox;
3819 GtkWidget *notebook;
3823 GtkWidget *table_vbox;
3825 GtkWidget *from_optmenu_hbox;
3826 #if 0 /* NEW COMPOSE GUI */
3827 GtkWidget *to_entry;
3829 GtkWidget *newsgroups_entry;
3830 GtkWidget *newsgroups_hbox;
3832 GtkWidget *header_scrolledwin;
3833 GtkWidget *header_table;
3834 GtkWidget *subject_entry;
3835 #if 0 /* NEW COMPOSE GUI */
3836 GtkWidget *cc_entry;
3838 GtkWidget *bcc_entry;
3839 GtkWidget *bcc_hbox;
3840 GtkWidget *reply_entry;
3841 GtkWidget *reply_hbox;
3842 GtkWidget *followup_entry;
3843 GtkWidget *followup_hbox;
3847 GtkWidget *attach_scrwin;
3848 GtkWidget *attach_clist;
3850 GtkWidget *edit_vbox;
3851 GtkWidget *ruler_hbox;
3853 GtkWidget *scrolledwin;
3859 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
3860 guint n_menu_entries;
3861 GtkStyle *style, *new_style;
3864 gboolean success[1];
3866 GtkWidget *popupmenu;
3867 GtkWidget *menuitem;
3868 GtkItemFactory *popupfactory;
3869 GtkItemFactory *ifactory;
3870 GtkWidget *tmpl_menu;
3876 GtkPspell * gtkpspell = NULL;
3879 g_return_val_if_fail(account != NULL, NULL);
3881 debug_print(_("Creating compose window...\n"));
3882 compose = g_new0(Compose, 1);
3884 compose->account = account;
3885 compose->orig_account = account;
3887 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
3888 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
3889 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
3890 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
3891 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
3892 gtk_signal_connect(GTK_OBJECT(window), "destroy",
3893 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
3894 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
3895 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
3896 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
3897 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
3898 gtk_widget_realize(window);
3900 gtkut_widget_set_composer_icon(window);
3902 vbox = gtk_vbox_new(FALSE, 0);
3903 gtk_container_add(GTK_CONTAINER(window), vbox);
3905 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
3906 menubar = menubar_create(window, compose_entries,
3907 n_menu_entries, "<Compose>", compose);
3908 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
3910 handlebox = gtk_handle_box_new();
3911 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
3913 compose_toolbar_create(compose, handlebox);
3915 vbox2 = gtk_vbox_new(FALSE, 2);
3916 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
3917 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
3919 table_vbox = gtk_vbox_new(FALSE, 0);
3920 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
3921 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
3925 notebook = gtk_notebook_new();
3926 gtk_widget_set_usize(notebook, -1, 180);
3927 gtk_widget_show(notebook);
3929 /* header labels and entries */
3930 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
3931 gtk_widget_show(header_scrolledwin);
3932 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
3933 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), header_scrolledwin, gtk_label_new(_("Header")));
3935 header_table = gtk_table_new(2, 2, FALSE);
3936 gtk_widget_show(header_table);
3937 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
3938 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
3941 /* option menu for selecting accounts */
3942 hbox = gtk_hbox_new(FALSE, 0);
3943 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
3944 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3945 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
3947 from_optmenu_hbox = compose_account_option_menu_create(compose);
3948 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
3949 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
3950 #if 0 /* NEW COMPOSE GUI */
3951 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
3956 compose_add_entry_field(header_table, &hbox, &subject_entry, &count,
3959 compose->header_table = header_table;
3960 compose->header_list = NULL;
3961 compose->header_nextrow = count;
3963 compose_create_header_entry(compose);
3965 #if 0 /* NEW COMPOSE GUI */
3966 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
3968 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
3969 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
3970 &count, "Newsgroups:", FALSE);
3971 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
3973 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
3975 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
3977 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
3978 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
3980 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
3981 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
3983 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
3984 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
3985 "Followup-To:", FALSE);
3986 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
3988 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
3990 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
3991 GTK_SIGNAL_FUNC(to_activated), compose);
3992 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
3993 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
3994 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
3995 GTK_SIGNAL_FUNC(subject_activated), compose);
3996 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
3997 GTK_SIGNAL_FUNC(cc_activated), compose);
3998 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
3999 GTK_SIGNAL_FUNC(bcc_activated), compose);
4000 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
4001 GTK_SIGNAL_FUNC(replyto_activated), compose);
4002 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
4003 GTK_SIGNAL_FUNC(followupto_activated), compose);
4005 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
4006 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4007 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
4008 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4009 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
4010 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4011 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
4012 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4013 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
4014 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4015 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
4016 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4017 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
4018 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4021 /* attachment list */
4022 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
4023 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), attach_scrwin, gtk_label_new(_("Attachments")));
4024 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
4025 GTK_POLICY_AUTOMATIC,
4027 gtk_widget_set_usize(attach_scrwin, -1, 80);
4029 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
4030 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
4032 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
4033 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
4034 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
4035 GTK_SELECTION_EXTENDED);
4036 for (i = 0; i < N_ATTACH_COLS; i++)
4037 GTK_WIDGET_UNSET_FLAGS
4038 (GTK_CLIST(attach_clist)->column[i].button,
4040 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
4042 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
4043 GTK_SIGNAL_FUNC(attach_selected), compose);
4044 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
4045 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
4046 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
4047 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
4050 gtk_drag_dest_set(attach_clist,
4051 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4053 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
4054 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
4058 edit_vbox = gtk_vbox_new(FALSE, 0);
4059 #if 0 /* NEW COMPOSE GUI */
4060 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
4064 ruler_hbox = gtk_hbox_new(FALSE, 0);
4065 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
4067 ruler = gtk_shruler_new();
4068 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
4069 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
4071 gtk_widget_set_usize(ruler_hbox, 1, -1);
4074 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
4075 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
4076 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
4077 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
4078 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
4080 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
4081 (GTK_SCROLLED_WINDOW(scrolledwin)),
4082 gtk_scrolled_window_get_vadjustment
4083 (GTK_SCROLLED_WINDOW(scrolledwin)));
4084 GTK_STEXT(text)->default_tab_width = 8;
4085 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
4087 if (prefs_common.block_cursor) {
4088 GTK_STEXT(text)->cursor_type = STEXT_CURSOR_BLOCK;
4091 if (prefs_common.smart_wrapping) {
4092 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
4093 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
4096 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
4098 gtk_signal_connect(GTK_OBJECT(text), "changed",
4099 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
4100 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
4101 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
4102 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
4103 GTK_SIGNAL_FUNC(compose_button_press_cb),
4106 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
4107 GTK_SIGNAL_FUNC(compose_key_press_cb),
4110 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
4111 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
4115 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
4117 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
4118 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
4121 if (prefs_common.enable_pspell) {
4122 gtkpspell = gtkpspell_new_with_config(gtkpspellconfig,
4123 prefs_common.pspell_path,
4124 prefs_common.dictionary,
4126 conv_get_current_charset_str());
4127 if (gtkpspell == NULL)
4128 prefs_common.enable_pspell = FALSE;
4130 gtkpspell_attach(gtkpspell, GTK_STEXT(text));
4133 gtk_widget_show_all(vbox);
4135 /* pane between attach clist and text */
4136 paned = gtk_vpaned_new();
4137 gtk_container_add(GTK_CONTAINER(vbox2), paned);
4138 gtk_paned_add1(GTK_PANED(paned), notebook);
4139 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
4140 gtk_widget_show_all(paned);
4142 style = gtk_widget_get_style(text);
4144 /* workaround for the slow down of GtkText when using Pixmap theme */
4145 if (style->engine) {
4146 GtkThemeEngine *engine;
4148 engine = style->engine;
4149 style->engine = NULL;
4150 new_style = gtk_style_copy(style);
4151 style->engine = engine;
4153 new_style = gtk_style_copy(style);
4155 if (prefs_common.textfont) {
4158 charset = conv_get_current_charset();
4159 if (MB_CUR_MAX == 1) {
4162 Xstrdup_a(fontstr, prefs_common.textfont, );
4163 if (fontstr && (p = strchr(fontstr, ',')) != NULL)
4165 font = gdk_font_load(fontstr);
4167 font = gdk_fontset_load(prefs_common.textfont);
4169 gdk_font_unref(new_style->font);
4170 new_style->font = font;
4174 gtk_widget_set_style(text, new_style);
4176 color[0] = quote_color;
4177 cmap = gdk_window_get_colormap(window->window);
4178 gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
4179 if (success[0] == FALSE) {
4180 g_warning("Compose: color allocation failed.\n");
4181 style = gtk_widget_get_style(text);
4182 quote_color = style->black;
4185 n_entries = sizeof(compose_popup_entries) /
4186 sizeof(compose_popup_entries[0]);
4187 popupmenu = menu_create_items(compose_popup_entries, n_entries,
4188 "<Compose>", &popupfactory,
4191 ifactory = gtk_item_factory_from_widget(menubar);
4192 menu_set_sensitive(ifactory, "/Edit/Undo", FALSE);
4193 menu_set_sensitive(ifactory, "/Edit/Redo", FALSE);
4195 tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tool/Template");
4196 #if 0 /* NEW COMPOSE GUI */
4197 if (account->protocol == A_NNTP) {
4198 gtk_widget_hide(to_hbox);
4199 gtk_widget_hide(to_entry);
4200 gtk_widget_hide(cc_hbox);
4201 gtk_widget_hide(cc_entry);
4202 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 0);
4203 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 0);
4205 gtk_widget_hide(newsgroups_hbox);
4206 gtk_widget_hide(newsgroups_entry);
4207 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
4209 menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
4213 switch (prefs_common.toolbar_style) {
4215 gtk_widget_hide(handlebox);
4218 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4222 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4226 gtk_toolbar_set_style(GTK_TOOLBAR(compose->toolbar),
4231 gtk_widget_show(window);
4233 address_completion_start(window);
4235 compose->window = window;
4236 compose->vbox = vbox;
4237 compose->menubar = menubar;
4238 compose->handlebox = handlebox;
4240 compose->vbox2 = vbox2;
4242 compose->table_vbox = table_vbox;
4243 compose->table = NULL;
4244 #if 0 /* NEW COMPOSE GUI */
4245 compose->table = table;
4246 compose->to_hbox = to_hbox;
4247 compose->to_entry = to_entry;
4248 compose->newsgroups_hbox = newsgroups_hbox;
4249 compose->newsgroups_entry = newsgroups_entry;
4251 compose->subject_entry = subject_entry;
4252 #if 0 /* NEW COMPOSE GUI */
4253 compose->cc_hbox = cc_hbox;
4254 compose->cc_entry = cc_entry;
4255 compose->bcc_hbox = bcc_hbox;
4256 compose->bcc_entry = bcc_entry;
4257 compose->reply_hbox = reply_hbox;
4258 compose->reply_entry = reply_entry;
4259 compose->followup_hbox = followup_hbox;
4260 compose->followup_entry = followup_entry;
4262 compose->paned = paned;
4264 compose->attach_scrwin = attach_scrwin;
4265 compose->attach_clist = attach_clist;
4267 compose->edit_vbox = edit_vbox;
4268 compose->ruler_hbox = ruler_hbox;
4269 compose->ruler = ruler;
4270 compose->scrolledwin = scrolledwin;
4271 compose->text = text;
4273 compose->focused_editable = NULL;
4275 compose->popupmenu = popupmenu;
4276 compose->popupfactory = popupfactory;
4278 compose->tmpl_menu = tmpl_menu;
4280 compose->mode = mode;
4282 compose->targetinfo = NULL;
4283 compose->replyinfo = NULL;
4285 compose->replyto = NULL;
4286 compose->mailinglist = NULL;
4288 compose->bcc = NULL;
4289 compose->followup_to = NULL;
4290 compose->inreplyto = NULL;
4291 compose->references = NULL;
4292 compose->msgid = NULL;
4293 compose->boundary = NULL;
4296 compose->use_signing = FALSE;
4297 compose->use_encryption = FALSE;
4298 #endif /* USE_GPGME */
4300 compose->modified = FALSE;
4302 compose->return_receipt = FALSE;
4304 compose->to_list = NULL;
4305 compose->newsgroup_list = NULL;
4307 compose->exteditor_file = NULL;
4308 compose->exteditor_pid = -1;
4309 compose->exteditor_readdes = -1;
4310 compose->exteditor_tag = -1;
4312 compose->bounce_filename = NULL;
4314 compose_set_title(compose);
4316 #if 0 /* NEW COMPOSE GUI */
4317 compose->use_bcc = FALSE;
4318 compose->use_replyto = FALSE;
4319 compose->use_followupto = FALSE;
4323 compose->gtkpspell = gtkpspell;
4326 #if 0 /* NEW COMPOSE GUI */
4327 if (account->protocol != A_NNTP) {
4328 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
4329 gtk_check_menu_item_set_active
4330 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4331 gtk_widget_set_sensitive(menuitem, FALSE);
4332 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4333 gtk_check_menu_item_set_active
4334 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4335 gtk_widget_set_sensitive(menuitem, FALSE);
4338 if (account->set_autocc && account->auto_cc && mode != COMPOSE_REEDIT) {
4339 compose_entry_append(compose, account->auto_cc, COMPOSE_CC);
4340 #if 0 /* NEW COMPOSE GUI */
4341 compose->use_cc = TRUE;
4342 gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
4343 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
4344 gtk_check_menu_item_set_active
4345 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4348 if (account->set_autobcc) {
4349 compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
4350 #if 0 /* NEW COMPOSE GUI */
4351 compose->use_bcc = TRUE;
4352 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
4353 gtk_check_menu_item_set_active
4354 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4355 if (account->auto_bcc && mode != COMPOSE_REEDIT)
4356 gtk_entry_set_text(GTK_ENTRY(bcc_entry),
4360 if (account->set_autoreplyto && account->auto_replyto && mode != COMPOSE_REEDIT) {
4361 compose_entry_append(compose, account->auto_replyto, COMPOSE_REPLYTO);
4362 #if 0 /* NEW COMPOSE GUI */
4363 compose->use_replyto = TRUE;
4364 menuitem = gtk_item_factory_get_item(ifactory,
4365 "/Message/Reply to");
4366 gtk_check_menu_item_set_active
4367 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
4368 gtk_entry_set_text(GTK_ENTRY(reply_entry),
4369 account->auto_replyto);
4372 if (account->protocol != A_NNTP) {
4373 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), _("To:"));
4375 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), _("Newsgroups:"));
4378 menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
4379 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4380 prefs_common.show_ruler);
4383 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
4384 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4385 prefs_common.default_sign);
4386 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
4387 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
4388 prefs_common.default_encrypt);
4389 #endif /* USE_GPGME */
4391 addressbook_set_target_compose(compose);
4392 compose_set_template_menu(compose);
4394 compose_list = g_list_append(compose_list, compose);
4396 #if 0 /* NEW COMPOSE GUI */
4397 compose->use_to = FALSE;
4398 compose->use_cc = FALSE;
4399 compose->use_attach = TRUE;
4402 #if 0 /* NEW COMPOSE GUI */
4403 if (!compose->use_bcc) {
4404 gtk_widget_hide(bcc_hbox);
4405 gtk_widget_hide(bcc_entry);
4406 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
4408 if (!compose->use_replyto) {
4409 gtk_widget_hide(reply_hbox);
4410 gtk_widget_hide(reply_entry);
4411 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
4413 if (!compose->use_followupto) {
4414 gtk_widget_hide(followup_hbox);
4415 gtk_widget_hide(followup_entry);
4416 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
4419 if (!prefs_common.show_ruler)
4420 gtk_widget_hide(ruler_hbox);
4422 select_account(compose, account);
4427 #include "pixmaps/stock_mail_send.xpm"
4428 #include "pixmaps/stock_mail_send_queue.xpm"
4429 #include "pixmaps/stock_mail.xpm"
4430 #include "pixmaps/stock_paste.xpm"
4431 #include "pixmaps/stock_mail_attach.xpm"
4432 #include "pixmaps/stock_mail_compose.xpm"
4433 #include "pixmaps/linewrap.xpm"
4434 #include "pixmaps/tb_address_book.xpm"
4436 #define CREATE_TOOLBAR_ICON(xpm_d) \
4438 icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
4439 &container->style->white, \
4441 icon_wid = gtk_pixmap_new(icon, mask); \
4444 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
4449 GtkWidget *icon_wid;
4450 GtkWidget *send_btn;
4451 GtkWidget *sendl_btn;
4452 GtkWidget *draft_btn;
4453 GtkWidget *insert_btn;
4454 GtkWidget *attach_btn;
4456 GtkWidget *exteditor_btn;
4457 GtkWidget *linewrap_btn;
4458 GtkWidget *addrbook_btn;
4460 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
4462 gtk_container_add(GTK_CONTAINER(container), toolbar);
4463 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
4464 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
4465 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
4466 GTK_TOOLBAR_SPACE_LINE);
4468 CREATE_TOOLBAR_ICON(stock_mail_send_xpm);
4469 send_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4473 icon_wid, toolbar_send_cb, compose);
4475 CREATE_TOOLBAR_ICON(stock_mail_send_queue_xpm);
4476 /* CREATE_TOOLBAR_ICON(tb_mail_queue_send_xpm); */
4477 sendl_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4479 _("Put into queue folder and send later"),
4481 icon_wid, toolbar_send_later_cb,
4484 CREATE_TOOLBAR_ICON(stock_mail_xpm);
4485 draft_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4487 _("Save to draft folder"),
4489 icon_wid, toolbar_draft_cb,
4492 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4494 CREATE_TOOLBAR_ICON(stock_paste_xpm);
4495 insert_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4499 icon_wid, toolbar_insert_cb,
4502 CREATE_TOOLBAR_ICON(stock_mail_attach_xpm);
4503 attach_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4507 icon_wid, toolbar_attach_cb,
4510 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4512 CREATE_TOOLBAR_ICON(stock_mail_xpm);
4513 sig_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4515 _("Insert signature"),
4517 icon_wid, toolbar_sig_cb, compose);
4519 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4521 CREATE_TOOLBAR_ICON(stock_mail_compose_xpm);
4522 exteditor_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4524 _("Edit with external editor"),
4527 toolbar_ext_editor_cb,
4530 CREATE_TOOLBAR_ICON(linewrap_xpm);
4531 linewrap_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4533 _("Wrap current paragraph"),
4536 toolbar_linewrap_cb,
4539 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
4541 CREATE_TOOLBAR_ICON(tb_address_book_xpm);
4542 addrbook_btn = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
4546 icon_wid, toolbar_address_cb,
4549 compose->toolbar = toolbar;
4550 compose->send_btn = send_btn;
4551 compose->sendl_btn = sendl_btn;
4552 compose->draft_btn = draft_btn;
4553 compose->insert_btn = insert_btn;
4554 compose->attach_btn = attach_btn;
4555 compose->sig_btn = sig_btn;
4556 compose->exteditor_btn = exteditor_btn;
4557 compose->linewrap_btn = linewrap_btn;
4558 compose->addrbook_btn = addrbook_btn;
4560 gtk_widget_show_all(toolbar);
4563 #undef CREATE_TOOLBAR_ICON
4565 static GtkWidget *compose_account_option_menu_create(Compose *compose)
4571 gint num = 0, def_menu = 0;
4573 accounts = account_get_list();
4574 g_return_val_if_fail(accounts != NULL, NULL);
4576 hbox = gtk_hbox_new(FALSE, 0);
4577 optmenu = gtk_option_menu_new();
4578 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4579 menu = gtk_menu_new();
4581 for (; accounts != NULL; accounts = accounts->next, num++) {
4582 PrefsAccount *ac = (PrefsAccount *)accounts->data;
4583 GtkWidget *menuitem;
4586 if (ac == compose->account) def_menu = num;
4588 name = g_strdup_printf("%s: %s <%s>",
4589 ac->account_name, ac->name, ac->address);
4590 MENUITEM_ADD(menu, menuitem, name, ac);
4592 gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
4593 GTK_SIGNAL_FUNC(account_activated),
4597 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
4598 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), def_menu);
4603 static void compose_set_template_menu(Compose *compose)
4605 GSList *tmpl_list, *cur;
4609 tmpl_list = template_get_config();
4611 menu = gtk_menu_new();
4613 for (cur = tmpl_list; cur != NULL; cur = cur->next) {
4614 Template *tmpl = (Template *)cur->data;
4616 item = gtk_menu_item_new_with_label(tmpl->name);
4617 gtk_menu_append(GTK_MENU(menu), item);
4618 gtk_signal_connect(GTK_OBJECT(item), "activate",
4619 GTK_SIGNAL_FUNC(compose_template_activate_cb),
4621 gtk_object_set_data(GTK_OBJECT(item), "template", tmpl);
4622 gtk_widget_show(item);
4625 gtk_widget_show(menu);
4626 gtk_menu_item_set_submenu(GTK_MENU_ITEM(compose->tmpl_menu), menu);
4629 void compose_reflect_prefs_all(void)
4634 for (cur = compose_list; cur != NULL; cur = cur->next) {
4635 compose = (Compose *)cur->data;
4636 compose_set_template_menu(compose);
4640 static void compose_template_apply(Compose *compose, Template *tmpl)
4645 if (!tmpl || !tmpl->value) return;
4647 gtk_stext_freeze(GTK_STEXT(compose->text));
4650 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
4653 if (compose->replyinfo == NULL) {
4656 memset(&dummyinfo, 0, sizeof(MsgInfo));
4657 parsed_str = compose_quote_fmt(compose, &dummyinfo,
4660 if (prefs_common.quotemark && *prefs_common.quotemark)
4661 qmark = prefs_common.quotemark;
4665 parsed_str = compose_quote_fmt(compose, compose->replyinfo,
4666 tmpl->value, qmark);
4669 if (parsed_str && prefs_common.auto_sig)
4670 compose_insert_sig(compose);
4672 gtk_stext_thaw(GTK_STEXT(compose->text));
4675 static void compose_destroy(Compose *compose)
4678 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4681 /* NOTE: address_completion_end() does nothing with the window
4682 * however this may change. */
4683 address_completion_end(compose->window);
4685 slist_free_strings(compose->to_list);
4686 g_slist_free(compose->to_list);
4687 slist_free_strings(compose->newsgroup_list);
4688 g_slist_free(compose->newsgroup_list);
4689 slist_free_strings(compose->header_list);
4690 g_slist_free(compose->header_list);
4692 procmsg_msginfo_free(compose->targetinfo);
4693 procmsg_msginfo_free(compose->replyinfo);
4695 g_free(compose->replyto);
4696 g_free(compose->cc);
4697 g_free(compose->bcc);
4698 g_free(compose->newsgroups);
4699 g_free(compose->followup_to);
4701 g_free(compose->inreplyto);
4702 g_free(compose->references);
4703 g_free(compose->msgid);
4704 g_free(compose->boundary);
4706 if (compose->bounce_filename)
4707 g_free(compose->bounce_filename);
4709 g_free(compose->exteditor_file);
4711 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
4713 compose_attach_info_free(ainfo);
4715 if (addressbook_get_target_compose() == compose)
4716 addressbook_set_target_compose(NULL);
4718 prefs_common.compose_width = compose->scrolledwin->allocation.width;
4719 prefs_common.compose_height = compose->window->allocation.height;
4721 gtk_widget_destroy(compose->paned);
4725 compose_list = g_list_remove(compose_list, compose);
4728 static void compose_attach_info_free(AttachInfo *ainfo)
4730 g_free(ainfo->file);
4731 g_free(ainfo->content_type);
4732 g_free(ainfo->name);
4736 static void compose_attach_remove_selected(Compose *compose)
4738 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4742 while (clist->selection != NULL) {
4743 row = GPOINTER_TO_INT(clist->selection->data);
4744 ainfo = gtk_clist_get_row_data(clist, row);
4745 compose_attach_info_free(ainfo);
4746 gtk_clist_remove(clist, row);
4750 static struct _AttachProperty
4753 GtkWidget *mimetype_entry;
4754 GtkWidget *encoding_optmenu;
4755 GtkWidget *path_entry;
4756 GtkWidget *filename_entry;
4758 GtkWidget *cancel_btn;
4761 static void compose_attach_property(Compose *compose)
4763 GtkCList *clist = GTK_CLIST(compose->attach_clist);
4766 GtkOptionMenu *optmenu;
4767 static gboolean cancelled;
4769 if (!clist->selection) return;
4770 row = GPOINTER_TO_INT(clist->selection->data);
4772 ainfo = gtk_clist_get_row_data(clist, row);
4775 if (!attach_prop.window)
4776 compose_attach_property_create(&cancelled);
4777 gtk_widget_grab_focus(attach_prop.ok_btn);
4778 gtk_widget_show(attach_prop.window);
4779 manage_window_set_transient(GTK_WINDOW(attach_prop.window));
4781 optmenu = GTK_OPTION_MENU(attach_prop.encoding_optmenu);
4782 if (ainfo->encoding == ENC_UNKNOWN)
4783 gtk_option_menu_set_history(optmenu, ENC_BASE64);
4785 gtk_option_menu_set_history(optmenu, ainfo->encoding);
4787 gtk_entry_set_text(GTK_ENTRY(attach_prop.mimetype_entry),
4788 ainfo->content_type ? ainfo->content_type : "");
4789 gtk_entry_set_text(GTK_ENTRY(attach_prop.path_entry),
4790 ainfo->file ? ainfo->file : "");
4791 gtk_entry_set_text(GTK_ENTRY(attach_prop.filename_entry),
4792 ainfo->name ? ainfo->name : "");
4796 gchar *cnttype = NULL;
4800 GtkWidget *menuitem;
4805 if (cancelled == TRUE) {
4806 gtk_widget_hide(attach_prop.window);
4810 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.mimetype_entry));
4811 if (*text != '\0') {
4814 text = g_strstrip(g_strdup(text));
4815 if ((p = strchr(text, '/')) && !strchr(p + 1, '/')) {
4816 cnttype = g_strdup(text);
4819 alertpanel_error(_("Invalid MIME type."));
4825 menu = gtk_option_menu_get_menu(optmenu);
4826 menuitem = gtk_menu_get_active(GTK_MENU(menu));
4827 ainfo->encoding = GPOINTER_TO_INT
4828 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
4830 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.path_entry));
4831 if (*text != '\0') {
4832 if (is_file_exist(text) &&
4833 (size = get_file_size(text)) > 0)
4834 file = g_strdup(text);
4837 (_("File doesn't exist or is empty."));
4843 text = gtk_entry_get_text(GTK_ENTRY(attach_prop.filename_entry));
4844 if (*text != '\0') {
4845 g_free(ainfo->name);
4846 ainfo->name = g_strdup(text);
4850 g_free(ainfo->content_type);
4851 ainfo->content_type = cnttype;
4854 g_free(ainfo->file);
4860 gtk_clist_set_text(clist, row, COL_MIMETYPE,
4861 ainfo->content_type);
4862 gtk_clist_set_text(clist, row, COL_SIZE,
4863 to_human_readable(ainfo->size));
4864 gtk_clist_set_text(clist, row, COL_NAME, ainfo->name);
4866 gtk_widget_hide(attach_prop.window);
4871 #define SET_LABEL_AND_ENTRY(str, entry, top) \
4873 label = gtk_label_new(str); \
4874 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
4875 GTK_FILL, 0, 0, 0); \
4876 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
4878 entry = gtk_entry_new(); \
4879 gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
4880 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
4883 static void compose_attach_property_create(gboolean *cancelled)
4889 GtkWidget *mimetype_entry;
4892 GtkWidget *optmenu_menu;
4893 GtkWidget *menuitem;
4894 GtkWidget *path_entry;
4895 GtkWidget *filename_entry;
4898 GtkWidget *cancel_btn;
4899 GList *mime_type_list, *strlist;
4901 debug_print("Creating attach_property window...\n");
4903 window = gtk_window_new(GTK_WINDOW_DIALOG);
4904 gtk_widget_set_usize(window, 480, -1);
4905 gtk_container_set_border_width(GTK_CONTAINER(window), 8);
4906 gtk_window_set_title(GTK_WINDOW(window), _("Property"));
4907 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
4908 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
4909 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
4910 GTK_SIGNAL_FUNC(attach_property_delete_event),
4912 gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
4913 GTK_SIGNAL_FUNC(attach_property_key_pressed),
4916 vbox = gtk_vbox_new(FALSE, 8);
4917 gtk_container_add(GTK_CONTAINER(window), vbox);
4919 table = gtk_table_new(4, 2, FALSE);
4920 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
4921 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
4922 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
4924 label = gtk_label_new(_("MIME type"));
4925 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1),
4927 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
4928 mimetype_entry = gtk_combo_new();
4929 gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1),
4930 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
4932 /* stuff with list */
4933 mime_type_list = procmime_get_mime_type_list();
4935 for (; mime_type_list != NULL; mime_type_list = mime_type_list->next) {
4936 MimeType *type = (MimeType *) mime_type_list->data;
4937 strlist = g_list_append(strlist,
4938 g_strdup_printf("%s/%s",
4939 type->type, type->sub_type));
4942 gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
4944 for (mime_type_list = strlist; mime_type_list != NULL;
4945 mime_type_list = mime_type_list->next)
4946 g_free(mime_type_list->data);
4947 g_list_free(strlist);
4949 mimetype_entry = GTK_COMBO(mimetype_entry)->entry;
4951 label = gtk_label_new(_("Encoding"));
4952 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
4954 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
4956 hbox = gtk_hbox_new(FALSE, 0);
4957 gtk_table_attach(GTK_TABLE(table), hbox, 1, 2, 1, 2,
4958 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
4960 optmenu = gtk_option_menu_new();
4961 gtk_box_pack_start(GTK_BOX(hbox), optmenu, FALSE, FALSE, 0);
4963 optmenu_menu = gtk_menu_new();
4964 MENUITEM_ADD(optmenu_menu, menuitem, "7bit", ENC_7BIT);
4965 gtk_widget_set_sensitive(menuitem, FALSE);
4966 MENUITEM_ADD(optmenu_menu, menuitem, "8bit", ENC_8BIT);
4967 gtk_widget_set_sensitive(menuitem, FALSE);
4968 MENUITEM_ADD(optmenu_menu, menuitem, "quoted-printable", ENC_QUOTED_PRINTABLE);
4969 gtk_widget_set_sensitive(menuitem, FALSE);
4970 MENUITEM_ADD(optmenu_menu, menuitem, "base64", ENC_BASE64);
4972 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), optmenu_menu);
4974 SET_LABEL_AND_ENTRY(_("Path"), path_entry, 2);
4975 SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
4977 gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
4978 &cancel_btn, _("Cancel"), NULL, NULL);
4979 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
4980 gtk_widget_grab_default(ok_btn);
4982 gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
4983 GTK_SIGNAL_FUNC(attach_property_ok),
4985 gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
4986 GTK_SIGNAL_FUNC(attach_property_cancel),
4989 gtk_widget_show_all(vbox);
4991 attach_prop.window = window;
4992 attach_prop.mimetype_entry = mimetype_entry;
4993 attach_prop.encoding_optmenu = optmenu;
4994 attach_prop.path_entry = path_entry;
4995 attach_prop.filename_entry = filename_entry;
4996 attach_prop.ok_btn = ok_btn;
4997 attach_prop.cancel_btn = cancel_btn;
5000 #undef SET_LABEL_AND_ENTRY
5002 static void attach_property_ok(GtkWidget *widget, gboolean *cancelled)
5008 static void attach_property_cancel(GtkWidget *widget, gboolean *cancelled)
5014 static gint attach_property_delete_event(GtkWidget *widget, GdkEventAny *event,
5015 gboolean *cancelled)
5023 static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
5024 gboolean *cancelled)
5026 if (event && event->keyval == GDK_Escape) {
5032 static void compose_exec_ext_editor(Compose *compose)
5038 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
5039 g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
5041 if (pipe(pipe_fds) < 0) {
5046 if ((pid = fork()) < 0) {
5052 /* close the write side of the pipe */
5055 compose->exteditor_file = g_strdup(tmp);
5056 compose->exteditor_pid = pid;
5057 compose->exteditor_readdes = pipe_fds[0];
5059 compose_set_ext_editor_sensitive(compose, FALSE);
5061 compose->exteditor_tag =
5062 gdk_input_add(pipe_fds[0], GDK_INPUT_READ,
5063 compose_input_cb, compose);
5064 } else { /* process-monitoring process */
5070 /* close the read side of the pipe */
5073 if (compose_write_body_to_file(compose, tmp) < 0) {
5074 fd_write(pipe_fds[1], "2\n", 2);
5078 pid_ed = compose_exec_ext_editor_real(tmp);
5080 fd_write(pipe_fds[1], "1\n", 2);
5084 /* wait until editor is terminated */
5085 waitpid(pid_ed, NULL, 0);
5087 fd_write(pipe_fds[1], "0\n", 2);
5094 static gint compose_exec_ext_editor_real(const gchar *file)
5096 static gchar *def_cmd = "emacs %s";
5102 g_return_val_if_fail(file != NULL, -1);
5104 if ((pid = fork()) < 0) {
5109 if (pid != 0) return pid;
5111 /* grandchild process */
5113 if (setpgid(0, getppid()))
5116 if (prefs_common.ext_editor_cmd &&
5117 (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
5118 *(p + 1) == 's' && !strchr(p + 2, '%')) {
5119 g_snprintf(buf, sizeof(buf), prefs_common.ext_editor_cmd, file);
5121 if (prefs_common.ext_editor_cmd)
5122 g_warning(_("External editor command line is invalid: `%s'\n"),
5123 prefs_common.ext_editor_cmd);
5124 g_snprintf(buf, sizeof(buf), def_cmd, file);
5127 cmdline = g_strsplit(buf, " ", 1024);
5128 execvp(cmdline[0], cmdline);
5131 g_strfreev(cmdline);
5136 static gboolean compose_ext_editor_kill(Compose *compose)
5138 pid_t pgid = compose->exteditor_pid * -1;
5141 ret = kill(pgid, 0);
5143 if (ret == 0 || (ret == -1 && EPERM == errno)) {
5147 msg = g_strdup_printf
5148 (_("The external editor is still working.\n"
5149 "Force terminating the process?\n"
5150 "process group id: %d"), -pgid);
5151 val = alertpanel(_("Notice"), msg, _("Yes"), _("+No"), NULL);
5154 if (val == G_ALERTDEFAULT) {
5155 gdk_input_remove(compose->exteditor_tag);
5156 close(compose->exteditor_readdes);
5158 if (kill(pgid, SIGTERM) < 0) perror("kill");
5159 waitpid(compose->exteditor_pid, NULL, 0);
5161 g_warning(_("Terminated process group id: %d"), -pgid);
5162 g_warning(_("Temporary file: %s"),
5163 compose->exteditor_file);
5165 compose_set_ext_editor_sensitive(compose, TRUE);
5167 g_free(compose->exteditor_file);
5168 compose->exteditor_file = NULL;
5169 compose->exteditor_pid = -1;
5170 compose->exteditor_readdes = -1;
5171 compose->exteditor_tag = -1;
5179 static void compose_input_cb(gpointer data, gint source,
5180 GdkInputCondition condition)
5183 Compose *compose = (Compose *)data;
5186 debug_print(_("Compose: input from monitoring process\n"));
5188 gdk_input_remove(compose->exteditor_tag);
5191 if (read(source, &buf[i], 1) < 1) {
5195 if (buf[i] == '\n') {
5200 if (i == sizeof(buf) - 1)
5204 waitpid(compose->exteditor_pid, NULL, 0);
5206 if (buf[0] == '0') { /* success */
5207 GtkSText *text = GTK_STEXT(compose->text);
5209 gtk_stext_freeze(text);
5210 gtk_stext_set_point(text, 0);
5211 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
5212 compose_insert_file(compose, compose->exteditor_file);
5213 compose_changed_cb(NULL, compose);
5214 gtk_stext_thaw(text);
5216 if (unlink(compose->exteditor_file) < 0)
5217 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5218 } else if (buf[0] == '1') { /* failed */
5219 g_warning(_("Couldn't exec external editor\n"));
5220 if (unlink(compose->exteditor_file) < 0)
5221 FILE_OP_ERROR(compose->exteditor_file, "unlink");
5222 } else if (buf[0] == '2') {
5223 g_warning(_("Couldn't write to file\n"));
5224 } else if (buf[0] == '3') {
5225 g_warning(_("Pipe read failed\n"));
5230 compose_set_ext_editor_sensitive(compose, TRUE);
5232 g_free(compose->exteditor_file);
5233 compose->exteditor_file = NULL;
5234 compose->exteditor_pid = -1;
5235 compose->exteditor_readdes = -1;
5236 compose->exteditor_tag = -1;
5239 static void compose_set_ext_editor_sensitive(Compose *compose,
5242 GtkItemFactory *ifactory;
5244 ifactory = gtk_item_factory_from_widget(compose->menubar);
5246 menu_set_sensitive(ifactory, "/Message/Send", sensitive);
5247 menu_set_sensitive(ifactory, "/Message/Send later", sensitive);
5248 menu_set_sensitive(ifactory, "/Message/Save to draft folder",
5250 menu_set_sensitive(ifactory, "/File/Insert file", sensitive);
5251 menu_set_sensitive(ifactory, "/File/Insert signature", sensitive);
5252 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", sensitive);
5253 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", sensitive);
5254 menu_set_sensitive(ifactory, "/Edit/Edit with external editor",
5257 gtk_widget_set_sensitive(compose->text, sensitive);
5258 gtk_widget_set_sensitive(compose->send_btn, sensitive);
5259 gtk_widget_set_sensitive(compose->sendl_btn, sensitive);
5260 gtk_widget_set_sensitive(compose->draft_btn, sensitive);
5261 gtk_widget_set_sensitive(compose->insert_btn, sensitive);
5262 gtk_widget_set_sensitive(compose->sig_btn, sensitive);
5263 gtk_widget_set_sensitive(compose->exteditor_btn, sensitive);
5264 gtk_widget_set_sensitive(compose->linewrap_btn, sensitive);
5267 static gint calc_cursor_xpos(GtkSText *text, gint extra, gint char_width)
5271 cursor_pos = (text->cursor_pos_x - extra) / char_width;
5272 cursor_pos = MAX(cursor_pos, 0);
5277 /* callback functions */
5279 /* compose_edit_size_alloc() - called when resized. don't know whether Gtk
5280 * includes "non-client" (windows-izm) in calculation, so this calculation
5281 * may not be accurate.
5283 static gboolean compose_edit_size_alloc(GtkEditable *widget,
5284 GtkAllocation *allocation,
5285 GtkSHRuler *shruler)
5287 if (prefs_common.show_ruler) {
5289 gint line_width_in_chars;
5291 char_width = gtkut_get_font_width
5292 (GTK_WIDGET(widget)->style->font);
5293 line_width_in_chars =
5294 (allocation->width - allocation->x) / char_width;
5296 /* got the maximum */
5297 gtk_ruler_set_range(GTK_RULER(shruler),
5298 0.0, line_width_in_chars,
5299 calc_cursor_xpos(GTK_STEXT(widget),
5302 /*line_width_in_chars*/ char_width);
5308 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
5310 compose_send_cb(data, 0, NULL);
5313 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
5315 compose_send_later_cb(data, 0, NULL);
5318 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
5320 compose_draft_cb(data, 0, NULL);
5323 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
5325 compose_insert_file_cb(data, 0, NULL);
5328 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
5330 compose_attach_cb(data, 0, NULL);
5333 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
5335 Compose *compose = (Compose *)data;
5337 compose_insert_sig(compose);
5340 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
5342 Compose *compose = (Compose *)data;
5344 compose_exec_ext_editor(compose);
5347 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
5349 Compose *compose = (Compose *)data;
5351 compose_wrap_line(compose);
5354 static void toolbar_address_cb(GtkWidget *widget, gpointer data)
5356 compose_address_cb(data, 0, NULL);
5359 static void select_account(Compose * compose, PrefsAccount * ac)
5361 compose->account = ac;
5362 compose_set_title(compose);
5364 #if 0 /* NEW COMPOSE GUI */
5365 if (ac->protocol == A_NNTP) {
5366 GtkItemFactory *ifactory;
5367 GtkWidget *menuitem;
5369 ifactory = gtk_item_factory_from_widget(compose->menubar);
5370 menu_set_sensitive(ifactory,
5371 "/Message/Followup to", TRUE);
5372 gtk_widget_show(compose->newsgroups_hbox);
5373 gtk_widget_show(compose->newsgroups_entry);
5374 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5377 compose->use_to = FALSE;
5378 compose->use_cc = FALSE;
5380 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5381 gtk_check_menu_item_set_active
5382 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5384 menu_set_sensitive(ifactory,
5385 "/Message/To", TRUE);
5386 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5387 gtk_check_menu_item_set_active
5388 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
5390 gtk_widget_hide(compose->to_hbox);
5391 gtk_widget_hide(compose->to_entry);
5392 gtk_widget_hide(compose->cc_hbox);
5393 gtk_widget_hide(compose->cc_entry);
5394 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5396 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5400 GtkItemFactory *ifactory;
5401 GtkWidget *menuitem;
5403 ifactory = gtk_item_factory_from_widget(compose->menubar);
5404 menu_set_sensitive(ifactory,
5405 "/Message/Followup to", FALSE);
5406 gtk_entry_set_text(GTK_ENTRY(compose->newsgroups_entry), "");
5407 gtk_widget_hide(compose->newsgroups_hbox);
5408 gtk_widget_hide(compose->newsgroups_entry);
5409 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5412 compose->use_to = TRUE;
5413 compose->use_cc = TRUE;
5415 menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
5416 gtk_check_menu_item_set_active
5417 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5418 menu_set_sensitive(ifactory,
5419 "/Message/To", FALSE);
5420 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
5421 gtk_check_menu_item_set_active
5422 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
5423 gtk_widget_show(compose->to_hbox);
5424 gtk_widget_show(compose->to_entry);
5425 gtk_widget_show(compose->cc_hbox);
5426 gtk_widget_show(compose->cc_entry);
5428 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5430 gtk_table_set_row_spacing(GTK_TABLE(compose->table),
5433 gtk_widget_queue_resize(compose->table_vbox);
5437 static void account_activated(GtkMenuItem *menuitem, gpointer data)
5439 Compose *compose = (Compose *)data;
5443 ac = (PrefsAccount *)gtk_object_get_user_data(GTK_OBJECT(menuitem));
5444 g_return_if_fail(ac != NULL);
5446 if (ac != compose->account)
5447 select_account(compose, ac);
5450 static void attach_selected(GtkCList *clist, gint row, gint column,
5451 GdkEvent *event, gpointer data)
5453 Compose *compose = (Compose *)data;
5455 if (event && event->type == GDK_2BUTTON_PRESS)
5456 compose_attach_property(compose);
5459 static void attach_button_pressed(GtkWidget *widget, GdkEventButton *event,
5462 Compose *compose = (Compose *)data;
5463 GtkCList *clist = GTK_CLIST(compose->attach_clist);
5468 if (event->button == 3) {
5469 if ((clist->selection && !clist->selection->next) ||
5470 !clist->selection) {
5471 gtk_clist_unselect_all(clist);
5472 if (gtk_clist_get_selection_info(clist,
5475 gtk_clist_select_row(clist, row, column);
5476 gtkut_clist_set_focus_row(clist, row);
5479 gtk_menu_popup(GTK_MENU(compose->popupmenu), NULL, NULL,
5480 NULL, NULL, event->button, event->time);
5484 static void attach_key_pressed(GtkWidget *widget, GdkEventKey *event,
5487 Compose *compose = (Compose *)data;
5491 switch (event->keyval) {
5493 compose_attach_remove_selected(compose);
5498 static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
5500 Compose *compose = (Compose *)data;
5503 val = compose_send(compose);
5504 if (val == 0) gtk_widget_destroy(compose->window);
5507 static void compose_send_later_cb(gpointer data, guint action,
5510 Compose *compose = (Compose *)data;
5513 val = compose_queue(compose, NULL, NULL);
5514 if (!val) gtk_widget_destroy(compose->window);
5517 static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
5519 Compose *compose = (Compose *)data;
5523 draft = folder_get_default_draft();
5525 tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
5526 G_DIR_SEPARATOR, (gint)compose);
5528 if (compose_write_to_file(compose, tmp, TRUE) < 0) {
5533 folder_item_scan(draft);
5534 if (folder_item_add_msg(draft, tmp, TRUE) < 0) {
5541 if (compose->mode == COMPOSE_REEDIT) {
5542 compose_remove_reedit_target(compose);
5543 if (compose->targetinfo &&
5544 compose->targetinfo->folder != draft)
5545 folderview_update_item(compose->targetinfo->folder,
5549 folder_item_scan(draft);
5550 folderview_update_item(draft, TRUE);
5552 gtk_widget_destroy(compose->window);
5555 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
5557 Compose *compose = (Compose *)data;
5560 if (compose->bounce_filename != NULL)
5563 file_list = filesel_select_multiple_files(_("Select file"), NULL);
5568 for ( tmp = file_list; tmp; tmp = tmp->next) {
5569 gchar *file = (gchar *) tmp->data;
5570 compose_attach_append(compose, file, MIME_UNKNOWN);
5573 g_list_free(file_list);
5577 static void compose_insert_file_cb(gpointer data, guint action,
5580 Compose *compose = (Compose *)data;
5583 file_list = filesel_select_multiple_files(_("Select file"), NULL);
5588 for ( tmp = file_list; tmp; tmp = tmp->next) {
5589 gchar *file = (gchar *) tmp->data;
5590 compose_insert_file(compose, file);
5593 g_list_free(file_list);
5597 static gint compose_delete_cb(GtkWidget *widget, GdkEventAny *event,
5600 compose_close_cb(data, 0, NULL);
5604 static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
5606 Compose *compose = (Compose *)data;
5609 if (compose->exteditor_tag != -1) {
5610 if (!compose_ext_editor_kill(compose))
5614 if (compose->modified) {
5615 val = alertpanel(_("Discard message"),
5616 _("This message has been modified. discard it?"),
5617 _("Discard"), _("to Draft"), _("Cancel"));
5620 case G_ALERTDEFAULT:
5622 case G_ALERTALTERNATE:
5623 compose_draft_cb(data, 0, NULL);
5630 if (compose->gtkpspell) {
5631 gtkpspell_detach(compose->gtkpspell);
5632 compose->gtkpspell = gtkpspell_delete(compose->gtkpspell);
5635 gtk_widget_destroy(compose->window);
5638 static void compose_address_cb(gpointer data, guint action, GtkWidget *widget)
5640 Compose *compose = (Compose *)data;
5642 addressbook_open(compose);
5645 static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
5647 Compose *compose = (Compose *)data;
5650 tmpl = gtk_object_get_data(GTK_OBJECT(widget), "template");
5651 g_return_if_fail(tmpl != NULL);
5653 compose_template_apply(compose, tmpl);
5656 static void compose_ext_editor_cb(gpointer data, guint action,
5659 Compose *compose = (Compose *)data;
5661 compose_exec_ext_editor(compose);
5664 static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
5666 compose_destroy(compose);
5669 static void compose_cut_cb(Compose *compose)
5671 if (compose->focused_editable &&
5672 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5673 gtk_editable_cut_clipboard
5674 (GTK_EDITABLE(compose->focused_editable));
5677 static void compose_copy_cb(Compose *compose)
5679 if (compose->focused_editable &&
5680 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5681 gtk_editable_copy_clipboard
5682 (GTK_EDITABLE(compose->focused_editable));
5685 static void compose_paste_cb(Compose *compose)
5687 if (compose->focused_editable &&
5688 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5689 gtk_editable_paste_clipboard
5690 (GTK_EDITABLE(compose->focused_editable));
5693 static void compose_allsel_cb(Compose *compose)
5695 if (compose->focused_editable &&
5696 GTK_WIDGET_HAS_FOCUS(compose->focused_editable))
5697 gtk_editable_select_region
5698 (GTK_EDITABLE(compose->focused_editable), 0, -1);
5701 static void compose_grab_focus_cb(GtkWidget *widget, Compose *compose)
5703 if (GTK_IS_EDITABLE(widget))
5704 compose->focused_editable = widget;
5707 static void compose_changed_cb(GtkEditable *editable, Compose *compose)
5709 if (compose->modified == FALSE) {
5710 compose->modified = TRUE;
5711 compose_set_title(compose);
5715 static void compose_button_press_cb(GtkWidget *widget, GdkEventButton *event,
5718 gtk_stext_set_point(GTK_STEXT(widget),
5719 gtk_editable_get_position(GTK_EDITABLE(widget)));
5723 static void compose_key_press_cb(GtkWidget *widget, GdkEventKey *event,
5726 gtk_stext_set_point(GTK_STEXT(widget),
5727 gtk_editable_get_position(GTK_EDITABLE(widget)));
5731 #if 0 /* NEW COMPOSE GUI */
5732 static void compose_toggle_to_cb(gpointer data, guint action,
5735 Compose *compose = (Compose *)data;
5737 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5738 gtk_widget_show(compose->to_hbox);
5739 gtk_widget_show(compose->to_entry);
5740 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
5741 compose->use_to = TRUE;
5743 gtk_widget_hide(compose->to_hbox);
5744 gtk_widget_hide(compose->to_entry);
5745 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 0);
5746 gtk_widget_queue_resize(compose->table_vbox);
5747 compose->use_to = FALSE;
5750 if (addressbook_get_target_compose() == compose)
5751 addressbook_set_target_compose(compose);
5754 static void compose_toggle_cc_cb(gpointer data, guint action,
5757 Compose *compose = (Compose *)data;
5759 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5760 gtk_widget_show(compose->cc_hbox);
5761 gtk_widget_show(compose->cc_entry);
5762 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 4);
5763 compose->use_cc = TRUE;
5765 gtk_widget_hide(compose->cc_hbox);
5766 gtk_widget_hide(compose->cc_entry);
5767 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 3, 0);
5768 gtk_widget_queue_resize(compose->table_vbox);
5769 compose->use_cc = FALSE;
5772 if (addressbook_get_target_compose() == compose)
5773 addressbook_set_target_compose(compose);
5776 static void compose_toggle_bcc_cb(gpointer data, guint action,
5779 Compose *compose = (Compose *)data;
5781 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5782 gtk_widget_show(compose->bcc_hbox);
5783 gtk_widget_show(compose->bcc_entry);
5784 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 4);
5785 compose->use_bcc = TRUE;
5787 gtk_widget_hide(compose->bcc_hbox);
5788 gtk_widget_hide(compose->bcc_entry);
5789 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 4, 0);
5790 gtk_widget_queue_resize(compose->table_vbox);
5791 compose->use_bcc = FALSE;
5794 if (addressbook_get_target_compose() == compose)
5795 addressbook_set_target_compose(compose);
5798 static void compose_toggle_replyto_cb(gpointer data, guint action,
5801 Compose *compose = (Compose *)data;
5803 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5804 gtk_widget_show(compose->reply_hbox);
5805 gtk_widget_show(compose->reply_entry);
5806 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 4);
5807 compose->use_replyto = TRUE;
5809 gtk_widget_hide(compose->reply_hbox);
5810 gtk_widget_hide(compose->reply_entry);
5811 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 5, 0);
5812 gtk_widget_queue_resize(compose->table_vbox);
5813 compose->use_replyto = FALSE;
5817 static void compose_toggle_followupto_cb(gpointer data, guint action,
5820 Compose *compose = (Compose *)data;
5822 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5823 gtk_widget_show(compose->followup_hbox);
5824 gtk_widget_show(compose->followup_entry);
5825 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 4);
5826 compose->use_followupto = TRUE;
5828 gtk_widget_hide(compose->followup_hbox);
5829 gtk_widget_hide(compose->followup_entry);
5830 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 6, 0);
5831 gtk_widget_queue_resize(compose->table_vbox);
5832 compose->use_followupto = FALSE;
5836 static void compose_toggle_attach_cb(gpointer data, guint action,
5839 Compose *compose = (Compose *)data;
5841 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5842 gtk_widget_ref(compose->edit_vbox);
5844 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
5845 compose->edit_vbox);
5846 gtk_paned_add2(GTK_PANED(compose->paned), compose->edit_vbox);
5847 gtk_box_pack_start(GTK_BOX(compose->vbox2), compose->paned,
5849 gtk_widget_show(compose->paned);
5851 gtk_widget_unref(compose->edit_vbox);
5852 gtk_widget_unref(compose->paned);
5854 compose->use_attach = TRUE;
5856 gtk_widget_ref(compose->paned);
5857 gtk_widget_ref(compose->edit_vbox);
5859 gtk_container_remove(GTK_CONTAINER(compose->vbox2),
5861 gtk_container_remove(GTK_CONTAINER(compose->paned),
5862 compose->edit_vbox);
5863 gtk_box_pack_start(GTK_BOX(compose->vbox2),
5864 compose->edit_vbox, TRUE, TRUE, 0);
5866 gtk_widget_unref(compose->edit_vbox);
5868 compose->use_attach = FALSE;
5874 static void compose_toggle_sign_cb(gpointer data, guint action,
5877 Compose *compose = (Compose *)data;
5879 if (GTK_CHECK_MENU_ITEM(widget)->active)
5880 compose->use_signing = TRUE;
5882 compose->use_signing = FALSE;
5885 static void compose_toggle_encrypt_cb(gpointer data, guint action,
5888 Compose *compose = (Compose *)data;
5890 if (GTK_CHECK_MENU_ITEM(widget)->active)
5891 compose->use_encryption = TRUE;
5893 compose->use_encryption = FALSE;
5895 #endif /* USE_GPGME */
5897 static void compose_toggle_ruler_cb(gpointer data, guint action,
5900 Compose *compose = (Compose *)data;
5902 if (GTK_CHECK_MENU_ITEM(widget)->active) {
5903 gtk_widget_show(compose->ruler_hbox);
5904 prefs_common.show_ruler = TRUE;
5906 gtk_widget_hide(compose->ruler_hbox);
5907 gtk_widget_queue_resize(compose->edit_vbox);
5908 prefs_common.show_ruler = FALSE;
5912 static void compose_attach_drag_received_cb (GtkWidget *widget,
5913 GdkDragContext *drag_context,
5916 GtkSelectionData *data,
5921 Compose *compose = (Compose *)user_data;
5924 list = uri_list_extract_filenames((const gchar *)data->data);
5925 for (tmp = list; tmp != NULL; tmp = tmp->next)
5926 compose_attach_append(compose, (const gchar *)tmp->data,
5928 list_free_strings(list);
5932 static void compose_insert_drag_received_cb (GtkWidget *widget,
5933 GdkDragContext *drag_context,
5936 GtkSelectionData *data,
5941 Compose *compose = (Compose *)user_data;
5944 list = uri_list_extract_filenames((const gchar *)data->data);
5945 for (tmp = list; tmp != NULL; tmp = tmp->next)
5946 compose_insert_file(compose, (const gchar *)tmp->data);
5947 list_free_strings(list);
5951 #if 0 /* NEW COMPOSE GUI */
5952 static void to_activated(GtkWidget *widget, Compose *compose)
5954 if (GTK_WIDGET_VISIBLE(compose->newsgroups_entry))
5955 gtk_widget_grab_focus(compose->newsgroups_entry);
5957 gtk_widget_grab_focus(compose->subject_entry);
5960 static void newsgroups_activated(GtkWidget *widget, Compose *compose)
5962 gtk_widget_grab_focus(compose->subject_entry);
5965 static void subject_activated(GtkWidget *widget, Compose *compose)
5967 if (GTK_WIDGET_VISIBLE(compose->cc_entry))
5968 gtk_widget_grab_focus(compose->cc_entry);
5969 else if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
5970 gtk_widget_grab_focus(compose->bcc_entry);
5971 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
5972 gtk_widget_grab_focus(compose->reply_entry);
5973 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
5974 gtk_widget_grab_focus(compose->followup_entry);
5976 gtk_widget_grab_focus(compose->text);
5979 static void cc_activated(GtkWidget *widget, Compose *compose)
5981 if (GTK_WIDGET_VISIBLE(compose->bcc_entry))
5982 gtk_widget_grab_focus(compose->bcc_entry);
5983 else if (GTK_WIDGET_VISIBLE(compose->reply_entry))
5984 gtk_widget_grab_focus(compose->reply_entry);
5985 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
5986 gtk_widget_grab_focus(compose->followup_entry);
5988 gtk_widget_grab_focus(compose->text);
5991 static void bcc_activated(GtkWidget *widget, Compose *compose)
5993 if (GTK_WIDGET_VISIBLE(compose->reply_entry))
5994 gtk_widget_grab_focus(compose->reply_entry);
5995 else if (GTK_WIDGET_VISIBLE(compose->followup_entry))
5996 gtk_widget_grab_focus(compose->followup_entry);
5998 gtk_widget_grab_focus(compose->text);
6001 static void replyto_activated(GtkWidget *widget, Compose *compose)
6003 if (GTK_WIDGET_VISIBLE(compose->followup_entry))
6004 gtk_widget_grab_focus(compose->followup_entry);
6006 gtk_widget_grab_focus(compose->text);
6009 static void followupto_activated(GtkWidget *widget, Compose *compose)
6011 gtk_widget_grab_focus(compose->text);
6015 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
6018 Compose *compose = (Compose *)data;
6020 if (GTK_CHECK_MENU_ITEM(widget)->active)
6021 compose->return_receipt = TRUE;
6023 compose->return_receipt = FALSE;
6026 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
6028 ComposeHeaderEntry *headerentry)
6030 if ((g_slist_length(headerentry->compose->header_list) > 0) &&
6031 ((headerentry->headernum + 1) != headerentry->compose->header_nextrow) &&
6032 !(event->state & GDK_MODIFIER_MASK) &&
6033 (event->keyval == GDK_BackSpace) &&
6034 (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) == 0)) {
6035 gtk_container_remove
6036 (GTK_CONTAINER(headerentry->compose->header_table),
6037 headerentry->combo);
6038 gtk_container_remove
6039 (GTK_CONTAINER(headerentry->compose->header_table),
6040 headerentry->entry);
6041 headerentry->compose->header_list =
6042 g_slist_remove(headerentry->compose->header_list,
6044 g_free(headerentry);
6048 void compose_headerentry_changed_cb(GtkWidget *entry,
6049 ComposeHeaderEntry *headerentry)
6051 if (strlen(gtk_entry_get_text(GTK_ENTRY(entry))) != 0) {
6052 headerentry->compose->header_list =
6053 g_slist_append(headerentry->compose->header_list,
6055 compose_create_header_entry(headerentry->compose);
6056 gtk_signal_disconnect_by_func
6058 GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),