2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtkmain.h>
29 #include <gtk/gtkmenu.h>
30 #include <gtk/gtkmenuitem.h>
31 #include <gtk/gtkitemfactory.h>
32 #include <gtk/gtkcheckmenuitem.h>
33 #include <gtk/gtkoptionmenu.h>
34 #include <gtk/gtkwidget.h>
35 #include <gtk/gtkclist.h>
36 #include <gtk/gtkctree.h>
37 #include <gtk/gtkvpaned.h>
38 #include <gtk/gtkentry.h>
39 #include <gtk/gtkeditable.h>
40 #include <gtk/gtkwindow.h>
41 #include <gtk/gtksignal.h>
42 #include <gtk/gtkvbox.h>
43 #include <gtk/gtkcontainer.h>
44 #include <gtk/gtkhandlebox.h>
45 #include <gtk/gtktoolbar.h>
46 #include <gtk/gtktable.h>
47 #include <gtk/gtkhbox.h>
48 #include <gtk/gtklabel.h>
49 #include <gtk/gtkscrolledwindow.h>
50 #include <gtk/gtkthemes.h>
51 #include <gtk/gtkdnd.h>
58 /* #include <sys/utsname.h> */
64 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
74 #include "mainwindow.h"
76 #include "addressbook.h"
77 #include "folderview.h"
82 #include "customheader.h"
83 #include "prefs_common.h"
84 #include "prefs_account.h"
87 #include "procheader.h"
89 #include "statusbar.h"
96 #include "alertpanel.h"
97 #include "manage_window.h"
98 #include "gtkshruler.h"
100 #include "addr_compl.h"
101 #include "quote_fmt.h"
102 #include "template.h"
105 # include "rfc2015.h"
115 #define N_ATTACH_COLS 3
117 #define B64_LINE_SIZE 57
118 #define B64_BUFFSIZE 77
120 #define MAX_REFERENCES_LEN 999
122 static GdkColor quote_color = {0, 0, 0, 0xbfff};
124 static GList *compose_list = NULL;
126 static Compose *compose_create (PrefsAccount *account,
128 static void compose_toolbar_create (Compose *compose,
129 GtkWidget *container);
130 static GtkWidget *compose_account_option_menu_create
132 static void compose_set_template_menu (Compose *compose);
133 static void compose_destroy (Compose *compose);
135 static gint compose_parse_header (Compose *compose,
137 static gchar *compose_parse_references (const gchar *ref,
140 static gchar *compose_quote_fmt (Compose *compose,
145 static void compose_reply_set_entry (Compose *compose,
150 followup_and_reply_to);
151 static void compose_reedit_set_entry (Compose *compose,
153 static void compose_insert_sig (Compose *compose);
154 static void compose_insert_file (Compose *compose,
156 static void compose_attach_append (Compose *compose,
158 ContentType cnttype);
159 static void compose_attach_append_with_type(Compose *compose,
162 ContentType cnttype);
163 static void compose_wrap_line (Compose *compose);
164 static void compose_wrap_line_all (Compose *compose);
165 static void compose_set_title (Compose *compose);
167 static PrefsAccount *compose_current_mail_account(void);
168 /* static gint compose_send (Compose *compose); */
169 static gint compose_write_to_file (Compose *compose,
172 static gint compose_write_body_to_file (Compose *compose,
174 static gint compose_save_to_outbox (Compose *compose,
176 static gint compose_remove_reedit_target (Compose *compose);
177 static gint compose_queue (Compose *compose,
179 static void compose_write_attach (Compose *compose,
181 static gint compose_write_headers (Compose *compose,
183 const gchar *charset,
184 EncodingType encoding,
187 static void compose_convert_header (gchar *dest,
191 static void compose_generate_msgid (Compose *compose,
195 static void compose_attach_info_free (AttachInfo *ainfo);
196 static void compose_attach_remove_selected (Compose *compose);
198 static void compose_attach_property (Compose *compose);
199 static void compose_attach_property_create (gboolean *cancelled);
200 static void attach_property_ok (GtkWidget *widget,
201 gboolean *cancelled);
202 static void attach_property_cancel (GtkWidget *widget,
203 gboolean *cancelled);
204 static gint attach_property_delete_event (GtkWidget *widget,
206 gboolean *cancelled);
207 static void attach_property_key_pressed (GtkWidget *widget,
209 gboolean *cancelled);
211 static void compose_exec_ext_editor (Compose *compose);
212 static gint compose_exec_ext_editor_real (const gchar *file);
213 static gboolean compose_ext_editor_kill (Compose *compose);
214 static void compose_input_cb (gpointer data,
216 GdkInputCondition condition);
217 static void compose_set_ext_editor_sensitive (Compose *compose,
220 static gint calc_cursor_xpos (GtkSText *text,
224 static void compose_create_header_entry (Compose *compose);
225 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
227 /* callback functions */
229 static gboolean compose_edit_size_alloc (GtkEditable *widget,
230 GtkAllocation *allocation,
231 GtkSHRuler *shruler);
233 static void toolbar_send_cb (GtkWidget *widget,
235 static void toolbar_send_later_cb (GtkWidget *widget,
237 static void toolbar_draft_cb (GtkWidget *widget,
239 static void toolbar_insert_cb (GtkWidget *widget,
241 static void toolbar_attach_cb (GtkWidget *widget,
243 static void toolbar_sig_cb (GtkWidget *widget,
245 static void toolbar_ext_editor_cb (GtkWidget *widget,
247 static void toolbar_linewrap_cb (GtkWidget *widget,
249 static void toolbar_address_cb (GtkWidget *widget,
253 static void select_account(Compose * compose, PrefsAccount * ac);
254 static void account_activated (GtkMenuItem *menuitem,
257 static void attach_selected (GtkCList *clist,
262 static void attach_button_pressed (GtkWidget *widget,
263 GdkEventButton *event,
265 static void attach_key_pressed (GtkWidget *widget,
269 static void compose_send_cb (gpointer data,
272 static void compose_send_later_cb (gpointer data,
276 static void compose_draft_cb (gpointer data,
280 static void compose_attach_cb (gpointer data,
283 static void compose_insert_file_cb (gpointer data,
287 static void compose_close_cb (gpointer data,
291 static void compose_address_cb (gpointer data,
294 static void compose_template_activate_cb(GtkWidget *widget,
297 static void compose_ext_editor_cb (gpointer data,
301 static gint compose_delete_cb (GtkWidget *widget,
304 static void compose_destroy_cb (GtkWidget *widget,
307 static void compose_cut_cb (Compose *compose);
308 static void compose_copy_cb (Compose *compose);
309 static void compose_paste_cb (Compose *compose);
310 static void compose_allsel_cb (Compose *compose);
312 static void compose_grab_focus_cb (GtkWidget *widget,
315 static void compose_changed_cb (GtkEditable *editable,
317 static void compose_button_press_cb (GtkWidget *widget,
318 GdkEventButton *event,
321 static void compose_key_press_cb (GtkWidget *widget,
326 static void compose_toggle_to_cb (gpointer data,
329 static void compose_toggle_cc_cb (gpointer data,
332 static void compose_toggle_bcc_cb (gpointer data,
335 static void compose_toggle_replyto_cb (gpointer data,
338 static void compose_toggle_followupto_cb(gpointer data,
341 static void compose_toggle_attach_cb (gpointer data,
344 static void compose_toggle_ruler_cb (gpointer data,
348 static void compose_toggle_sign_cb (gpointer data,
351 static void compose_toggle_encrypt_cb (gpointer data,
355 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
358 static void compose_attach_drag_received_cb (GtkWidget *widget,
359 GdkDragContext *drag_context,
362 GtkSelectionData *data,
366 static void compose_insert_drag_received_cb (GtkWidget *widget,
367 GdkDragContext *drag_context,
370 GtkSelectionData *data,
375 static void to_activated (GtkWidget *widget,
377 static void newsgroups_activated (GtkWidget *widget,
379 static void subject_activated (GtkWidget *widget,
381 static void cc_activated (GtkWidget *widget,
383 static void bcc_activated (GtkWidget *widget,
385 static void replyto_activated (GtkWidget *widget,
387 static void followupto_activated (GtkWidget *widget,
389 static void compose_attach_parts(Compose * compose,
392 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
394 gboolean ignore_replyto,
395 gboolean followup_and_reply_to);
397 void compose_headerentry_changed_cb (GtkWidget *entry,
398 compose_headerentry *headerentry);
399 void compose_headerentry_key_press_event_cb (GtkWidget *entry,
401 compose_headerentry *headerentry);
403 Compose * compose_generic_new (PrefsAccount *account,
407 static GtkItemFactoryEntry compose_popup_entries[] =
409 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
410 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
411 {N_("/---"), NULL, NULL, 0, "<Separator>"},
412 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
415 static GtkItemFactoryEntry compose_entries[] =
417 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
418 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
419 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
420 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
421 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
422 {N_("/_File/_Close"), "<alt>W", compose_close_cb, 0, NULL},
424 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
425 {N_("/_Edit/_Undo"), "<control>Z", NULL, 0, NULL},
426 {N_("/_Edit/_Redo"), "<control>Y", NULL, 0, NULL},
427 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
428 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
429 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
430 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
431 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
432 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
433 {N_("/_Edit/_Wrap current paragraph"), "<alt>L", compose_wrap_line, 0, NULL},
434 {N_("/_Edit/Wrap all long _lines"),
435 "<shift><alt>L", compose_wrap_line_all, 0, NULL},
436 {N_("/_Edit/Edit with e_xternal editor"),
437 "<alt>X", compose_ext_editor_cb, 0, NULL},
439 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
440 {N_("/_Message/_Send"), "<control>Return",
441 compose_send_cb, 0, NULL},
442 {N_("/_Message/Send _later"), "<shift><alt>S",
443 compose_send_later_cb, 0, NULL},
444 {N_("/_Message/Save to _draft folder"),
445 "<alt>D", compose_draft_cb, 0, NULL},
446 #if 0 /* NEW COMPOSE GUI */
447 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
448 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
449 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
450 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
451 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
452 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
453 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
454 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
455 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
458 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
459 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
460 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
461 #endif /* USE_GPGME */
462 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
463 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
464 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
465 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
466 {N_("/_Tool/_Address book"), "<alt>A", compose_address_cb , 0, NULL},
467 {N_("/_Tool/_Template"), NULL, NULL, 0, "<Branch>"},
468 {N_("/_Help"), NULL, NULL, 0, "<LastBranch>"},
469 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
472 static GtkTargetEntry compose_mime_types[] =
474 {"text/uri-list", 0, 0}
477 Compose * compose_new(PrefsAccount *account)
479 return compose_generic_new(account, NULL, NULL);
482 Compose * compose_new_with_recipient(PrefsAccount *account, const gchar *to)
484 return compose_generic_new(account, to, NULL);
487 Compose * compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
489 return compose_generic_new(account, NULL, item);
492 static void set_compose_entries(Compose * compose, const gchar * mailto)
494 gchar * subject = NULL;
503 Xstrdup_a(tmp_mailto, mailto, return);
507 p = strchr(cur, '?');
519 p = strchr(cur, '=');
527 p = strchr(cur, '&');
534 if (g_strcasecmp(field, "subject")==0) {
535 Xstrdup_a(subject, value, );
537 decode_uri(subject, value);
539 else if (g_strcasecmp(field, "cc")==0)
541 else if (g_strcasecmp(field, "bcc")==0)
543 else if (g_strcasecmp(field, "body")==0) {
544 Xstrdup_a(body, value, );
546 decode_uri(body, value);
552 compose_entry_append(compose, to, COMPOSE_TO);
554 gtk_widget_grab_focus(compose->text);
559 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
561 compose_entry_append(compose, cc, COMPOSE_CC);
563 compose_entry_append(compose, bcc, COMPOSE_BCC);
565 gtk_stext_insert(GTK_STEXT(compose->text),
566 NULL, NULL, NULL, body, -1);
567 gtk_stext_insert(GTK_STEXT(compose->text),
568 NULL, NULL, NULL, "\n", 1);
572 Compose * compose_generic_new(PrefsAccount *account, const gchar *to, FolderItem *item)
576 if (item && item->prefs && item->prefs->enable_default_account)
577 account = account_find_from_id(item->prefs->default_account);
579 if (!account) account = cur_account;
580 g_return_val_if_fail(account != NULL, NULL);
582 compose = compose_create(account, COMPOSE_NEW);
583 compose->replyinfo = NULL;
585 if (prefs_common.auto_sig)
586 compose_insert_sig(compose);
587 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
588 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
590 if (account->protocol != A_NNTP) {
592 set_compose_entries(compose, to);
594 } else if(item && item->prefs->enable_default_to) {
595 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
597 if (item && item->ret_rcpt) {
598 GtkItemFactory *ifactory;
600 ifactory = gtk_item_factory_from_widget(compose->menubar);
601 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
605 compose_entry_append(compose, to, COMPOSE_NEWSGROUPS);
608 gtk_widget_grab_focus(compose->subject_entry);
610 if (prefs_common.auto_exteditor)
611 compose_exec_ext_editor(compose);
616 #define CHANGE_FLAGS(msginfo) \
618 if (msginfo->folder->folder->change_flags != NULL) \
619 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
625 Compose * compose_new_followup_and_replyto(PrefsAccount *account,
626 const gchar *followupto, gchar * to)
630 if (!account) account = cur_account;
631 g_return_val_if_fail(account != NULL, NULL);
632 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
634 compose = compose_create(account, COMPOSE_NEW);
636 if (prefs_common.auto_sig)
637 compose_insert_sig(compose);
638 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
639 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
641 compose_entry_append(compose, to, COMPOSE_TO);
642 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
643 gtk_widget_grab_focus(compose->subject_entry);
649 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
650 gboolean ignore_replyto)
652 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE);
655 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
657 gboolean ignore_replyto)
659 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE);
662 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
664 gboolean ignore_replyto,
665 gboolean followup_and_reply_to)
668 PrefsAccount *account;
669 PrefsAccount *reply_account;
672 g_return_if_fail(msginfo != NULL);
673 g_return_if_fail(msginfo->folder != NULL);
676 /* select the account set in folderitem's property (if enabled) */
677 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
678 account = account_find_from_id(msginfo->folder->prefs->default_account);
680 /* select the account for the whole folder (IMAP / NNTP) */
682 account = msginfo->folder->folder->account;
684 /* select account by to: and cc: header if enabled */
685 if (prefs_common.reply_account_autosel) {
686 if (!account && msginfo->to) {
688 Xstrdup_a(to, msginfo->to, return);
690 account = account_find_from_address(to);
694 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
696 account = account_find_from_address(cc);
701 /* select current account */
702 if (!account) account = cur_account;
703 g_return_if_fail(account != NULL);
705 if (ignore_replyto && account->protocol == A_NNTP &&
706 !followup_and_reply_to) {
708 account_find_from_address(account->address);
710 reply_account = compose_current_mail_account();
714 reply_account = account;
716 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
717 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
719 CHANGE_FLAGS(msginfo);
721 compose = compose_create(account, COMPOSE_REPLY);
722 compose->replyinfo = procmsg_msginfo_copy(msginfo);
724 #if 0 /* NEW COMPOSE GUI */
725 if (followup_and_reply_to) {
726 gtk_widget_show(compose->to_hbox);
727 gtk_widget_show(compose->to_entry);
728 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
729 compose->use_to = TRUE;
732 if (msginfo->folder && msginfo->folder->ret_rcpt) {
733 GtkItemFactory *ifactory;
735 ifactory = gtk_item_factory_from_widget(compose->menubar);
736 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
739 if (compose_parse_header(compose, msginfo) < 0) return;
740 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
741 followup_and_reply_to);
743 text = GTK_STEXT(compose->text);
744 gtk_stext_freeze(text);
750 if (prefs_common.quotemark && *prefs_common.quotemark)
751 qmark = prefs_common.quotemark;
755 quote_str = compose_quote_fmt(compose, msginfo,
756 prefs_common.quotefmt,
760 if (prefs_common.auto_sig)
761 compose_insert_sig(compose);
762 gtk_editable_set_position(GTK_EDITABLE(text), 0);
763 gtk_stext_set_point(text, 0);
765 if (quote && prefs_common.linewrap_quote) {
766 compose_wrap_line_all(compose);
769 gtk_stext_thaw(text);
770 gtk_widget_grab_focus(compose->text);
772 if (prefs_common.auto_exteditor)
773 compose_exec_ext_editor(compose);
777 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
782 g_return_val_if_fail(mimeinfo != NULL, NULL);
784 base = mimeinfo->filename ? mimeinfo->filename
785 : mimeinfo->name ? mimeinfo->name : NULL;
787 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
788 filename = g_strdup_printf("%s%smimetmp%i.html",
795 base = base ? base : "";
796 base = g_basename(base);
798 filename = g_strdup_printf("%s%smimetmp%i",
806 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
812 static gchar * mime_extract_file(gchar * source, MimeInfo *partinfo)
816 if (!partinfo) return;
818 filename = procmime_get_file_name(partinfo);
820 if (procmime_get_part(filename, source, partinfo) < 0)
822 (_("Can't get the part of multipart message."));
827 static void compose_attach_parts(Compose * compose,
837 gint boundary_len = 0;
839 glong fpos, prev_fpos;
844 g_return_if_fail(msginfo != NULL);
848 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
849 mimeinfo = procmime_scan_mime_header(fp);
850 if (!mimeinfo) break;
852 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
853 rfc2015_is_encrypted(mimeinfo)) {
854 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED);
856 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
857 !msginfo->plaintext_file &&
858 !msginfo->decryption_failed) {
859 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
860 if (msginfo->plaintext_file &&
861 !msginfo->decryption_failed) {
869 #else /* !USE_GPGME */
870 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
871 mimeinfo = procmime_scan_mime_header(fp);
872 #endif /* USE_GPGME */
875 if (!mimeinfo) return;
876 if (mimeinfo->mime_type == MIME_TEXT)
879 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
881 g_return_if_fail(mimeinfo != NULL);
882 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
884 if (mimeinfo->mime_type == MIME_MULTIPART) {
885 g_return_if_fail(mimeinfo->boundary != NULL);
886 g_return_if_fail(mimeinfo->sub == NULL);
888 g_return_if_fail(fp != NULL);
890 boundary = mimeinfo->boundary;
893 boundary_len = strlen(boundary);
895 /* look for first boundary */
896 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
897 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
904 if ((fpos = ftell(fp)) < 0) {
910 for (npart = 0;; npart++) {
912 gboolean eom = FALSE;
916 partinfo = procmime_scan_mime_header(fp);
917 if (!partinfo) break;
920 procmime_mimeinfo_insert(mimeinfo, partinfo);
922 procmime_mimeinfo_free(partinfo);
924 /* look for next boundary */
926 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
927 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
928 if (buf[2 + boundary_len] == '-' &&
929 buf[2 + boundary_len + 1] == '-')
935 eom = TRUE; /* broken MIME message */
938 partinfo->size = fpos - prev_fpos - strlen(buf);
943 source = procmsg_get_message_file_path(msginfo);
945 g_return_if_fail(mimeinfo != NULL);
947 if (!mimeinfo->main && mimeinfo->parent)
949 filename = mime_extract_file(source, mimeinfo);
951 compose_attach_append_with_type(compose, filename,
952 mimeinfo->content_type,
953 mimeinfo->mime_type);
958 if (mimeinfo->sub && mimeinfo->sub->children)
960 filename = mime_extract_file(source, mimeinfo->sub);
962 compose_attach_append_with_type(compose, filename,
963 mimeinfo->content_type,
964 mimeinfo->sub->mime_type);
969 if (mimeinfo->children) {
972 child = mimeinfo->children;
974 filename = mime_extract_file(source, child);
976 compose_attach_append_with_type(compose, filename,
988 procmime_mimeinfo_free_all(mimeinfo);
992 #define INSERT_FW_HEADER(var, hdr) \
993 if (msginfo->var && *msginfo->var) { \
994 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
995 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
996 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
999 Compose *compose_forward(PrefsAccount * account, MsgInfo *msginfo,
1003 /* PrefsAccount *account; */
1006 g_return_val_if_fail(msginfo != NULL, NULL);
1007 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1009 account = msginfo->folder->folder->account;
1010 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1012 Xstrdup_a(to, msginfo->to, return);
1013 extract_address(to);
1014 account = account_find_from_address(to);
1017 if(!account && prefs_common.forward_account_autosel) {
1019 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1020 extract_address(cc);
1021 account = account_find_from_address(cc);
1025 if (account == NULL) {
1026 account = cur_account;
1028 account = msginfo->folder->folder->account;
1029 if (!account) account = cur_account;
1032 g_return_val_if_fail(account != NULL, NULL);
1034 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1035 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1036 CHANGE_FLAGS(msginfo);
1038 compose = compose_create(account, COMPOSE_FORWARD);
1040 if (msginfo->subject && *msginfo->subject) {
1041 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1042 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1046 text = GTK_STEXT(compose->text);
1047 gtk_stext_freeze(text);
1052 msgfile = procmsg_get_message_file_path(msginfo);
1053 if (!is_file_exist(msgfile))
1054 g_warning(_("%s: file not exist\n"), msgfile);
1056 compose_attach_append(compose, msgfile,
1057 MIME_MESSAGE_RFC822);
1064 if (prefs_common.fw_quotemark && *prefs_common.fw_quotemark)
1065 qmark = prefs_common.fw_quotemark;
1069 quote_str = compose_quote_fmt(compose, msginfo,
1070 prefs_common.fw_quotefmt, qmark);
1071 compose_attach_parts(compose, msginfo);
1074 if (prefs_common.auto_sig)
1075 compose_insert_sig(compose);
1076 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1077 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1079 gtk_stext_thaw(text);
1080 #if 0 /* NEW COMPOSE GUI */
1081 if (account->protocol != A_NNTP)
1082 gtk_widget_grab_focus(compose->to_entry);
1084 gtk_widget_grab_focus(compose->newsgroups_entry);
1086 gtk_widget_grab_focus(compose->header_last->entry);
1088 if (prefs_common.auto_exteditor)
1089 compose_exec_ext_editor(compose);
1094 #undef INSERT_FW_HEADER
1096 Compose * compose_forward_multiple(PrefsAccount * account,
1097 GSList *msginfo_list)
1104 g_return_val_if_fail(msginfo_list != NULL, NULL);
1106 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1107 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1111 if (account == NULL) {
1112 account = cur_account;
1114 account = msginfo->folder->folder->account;
1115 if (!account) account = cur_account;
1118 g_return_val_if_fail(account != NULL, NULL);
1120 compose = compose_create(account, COMPOSE_FORWARD);
1122 text = GTK_STEXT(compose->text);
1123 gtk_stext_freeze(text);
1125 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1126 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1127 if (!is_file_exist(msgfile))
1128 g_warning(_("%s: file not exist\n"), msgfile);
1130 compose_attach_append(compose, msgfile,
1131 MIME_MESSAGE_RFC822);
1135 if (prefs_common.auto_sig)
1136 compose_insert_sig(compose);
1137 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1138 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1140 gtk_stext_thaw(text);
1141 #if 0 /* NEW COMPOSE GUI */
1142 if (account->protocol != A_NNTP)
1143 gtk_widget_grab_focus(compose->to_entry);
1145 gtk_widget_grab_focus(compose->newsgroups_entry);
1151 void compose_reedit(MsgInfo *msginfo)
1154 PrefsAccount *account;
1157 gchar buf[BUFFSIZE];
1159 g_return_if_fail(msginfo != NULL);
1160 g_return_if_fail(msginfo->folder != NULL);
1162 account = msginfo->folder->folder->account;
1164 if(!account&& prefs_common.reedit_account_autosel) {
1165 gchar from[BUFFSIZE];
1166 if(!get_header_from_msginfo(msginfo,from,sizeof(from),"FROM:")){ /* Found a FROM header */
1167 extract_address(from);
1168 account = account_find_from_address(from);
1171 if (!account) account = cur_account;
1172 g_return_if_fail(account != NULL);
1174 compose = compose_create(account, COMPOSE_REEDIT);
1175 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1177 if (compose_parse_header(compose, msginfo) < 0) return;
1178 compose_reedit_set_entry(compose, msginfo);
1180 text = GTK_STEXT(compose->text);
1181 gtk_stext_freeze(text);
1183 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1184 g_warning(_("Can't get text part\n"));
1186 while (fgets(buf, sizeof(buf), fp) != NULL)
1187 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1190 compose_attach_parts(compose, msginfo);
1192 gtk_stext_thaw(text);
1193 gtk_widget_grab_focus(compose->text);
1195 if (prefs_common.auto_exteditor)
1196 compose_exec_ext_editor(compose);
1199 GList *compose_get_compose_list(void)
1201 return compose_list;
1204 void compose_entry_append(Compose *compose, const gchar *address,
1205 ComposeEntryType type)
1211 if (!address || *address == '\0') return;
1213 #if 0 /* NEW COMPOSE GUI */
1216 entry = GTK_ENTRY(compose->cc_entry);
1219 entry = GTK_ENTRY(compose->bcc_entry);
1221 case COMPOSE_NEWSGROUPS:
1222 entry = GTK_ENTRY(compose->newsgroups_entry);
1226 entry = GTK_ENTRY(compose->to_entry);
1230 text = gtk_entry_get_text(entry);
1232 gtk_entry_append_text(entry, ", ");
1233 gtk_entry_append_text(entry, address);
1241 header = N_("Bcc:");
1243 case COMPOSE_REPLYTO:
1244 header = N_("Reply-To:");
1246 case COMPOSE_NEWSGROUPS:
1247 header = N_("Newsgroups:");
1249 case COMPOSE_FOLLOWUPTO:
1250 header = N_( "Followup-To:");
1257 header = prefs_common.trans_hdr ? gettext(header) : header;
1259 compose_add_header_entry(compose, header, (gchar *)address);
1262 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1264 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1265 {"Cc:", NULL, FALSE},
1266 {"References:", NULL, FALSE},
1267 {"Bcc:", NULL, FALSE},
1268 {"Newsgroups:", NULL, FALSE},
1269 {"Followup-To:", NULL, FALSE},
1270 {"X-Mailing-List:", NULL, FALSE},
1271 {"X-BeenThere:", NULL, FALSE},
1272 {NULL, NULL, FALSE}};
1282 H_X_MAILING_LIST = 6,
1288 g_return_val_if_fail(msginfo != NULL, -1);
1290 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1291 procheader_get_header_fields(fp, hentry);
1294 if (hentry[H_REPLY_TO].body != NULL) {
1295 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1296 compose->replyto = hentry[H_REPLY_TO].body;
1297 hentry[H_REPLY_TO].body = NULL;
1299 if (hentry[H_CC].body != NULL) {
1300 conv_unmime_header_overwrite(hentry[H_CC].body);
1301 compose->cc = hentry[H_CC].body;
1302 hentry[H_CC].body = NULL;
1304 if (hentry[H_X_MAILING_LIST].body != NULL) {
1305 /* this is good enough to parse debian-devel */
1306 char * buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1307 g_return_val_if_fail(buf != NULL, -1 );
1308 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1309 compose->mailinglist = g_strdup(buf);
1311 g_free(hentry[H_X_MAILING_LIST].body);
1312 hentry[H_X_MAILING_LIST].body = NULL ;
1314 if (hentry[H_X_BEENTHERE].body != NULL) {
1315 /* this is good enough to parse the sylpheed-claws lists */
1316 char * buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1317 g_return_val_if_fail(buf != NULL, -1 );
1318 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1319 compose->mailinglist = g_strdup(buf);
1321 g_free(hentry[H_X_BEENTHERE].body);
1322 hentry[H_X_BEENTHERE].body = NULL ;
1324 if (hentry[H_REFERENCES].body != NULL) {
1325 if (compose->mode == COMPOSE_REEDIT)
1326 compose->references = hentry[H_REFERENCES].body;
1328 compose->references = compose_parse_references
1329 (hentry[H_REFERENCES].body, msginfo->msgid);
1330 g_free(hentry[H_REFERENCES].body);
1332 hentry[H_REFERENCES].body = NULL;
1334 if (hentry[H_BCC].body != NULL) {
1335 if (compose->mode == COMPOSE_REEDIT) {
1336 conv_unmime_header_overwrite(hentry[H_BCC].body);
1337 compose->bcc = hentry[H_BCC].body;
1339 g_free(hentry[H_BCC].body);
1340 hentry[H_BCC].body = NULL;
1342 if (hentry[H_NEWSGROUPS].body != NULL) {
1343 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1344 hentry[H_NEWSGROUPS].body = NULL;
1346 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1347 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1348 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1349 hentry[H_FOLLOWUP_TO].body = NULL;
1352 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1353 compose->inreplyto = g_strdup(msginfo->inreplyto);
1354 else if (compose->mode != COMPOSE_REEDIT &&
1355 msginfo->msgid && *msginfo->msgid) {
1356 compose->inreplyto = g_strdup(msginfo->msgid);
1358 if (!compose->references) {
1359 if (msginfo->inreplyto && *msginfo->inreplyto)
1360 compose->references =
1361 g_strdup_printf("<%s>\n\t<%s>",
1365 compose->references =
1366 g_strconcat("<", msginfo->msgid, ">",
1374 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1376 GSList *ref_id_list, *cur;
1380 ref_id_list = references_list_append(NULL, ref);
1381 if (!ref_id_list) return NULL;
1382 if (msgid && *msgid)
1383 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1388 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1389 /* "<" + Message-ID + ">" + CR+LF+TAB */
1390 len += strlen((gchar *)cur->data) + 5;
1392 if (len > MAX_REFERENCES_LEN) {
1393 /* remove second message-ID */
1394 if (ref_id_list && ref_id_list->next &&
1395 ref_id_list->next->next) {
1396 g_free(ref_id_list->next->data);
1397 ref_id_list = g_slist_remove
1398 (ref_id_list, ref_id_list->next->data);
1400 slist_free_strings(ref_id_list);
1401 g_slist_free(ref_id_list);
1408 new_ref = g_string_new("");
1409 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1410 if (new_ref->len > 0)
1411 g_string_append(new_ref, "\n\t");
1412 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1415 slist_free_strings(ref_id_list);
1416 g_slist_free(ref_id_list);
1418 new_ref_str = new_ref->str;
1419 g_string_free(new_ref, FALSE);
1424 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1425 const gchar *fmt, const gchar *qmark)
1427 GtkSText *text = GTK_STEXT(compose->text);
1428 gchar *quote_str = NULL;
1433 if (qmark != NULL) {
1434 quote_fmt_init(msginfo, NULL);
1435 quote_fmt_scan_string(qmark);
1438 buf = quote_fmt_get_buffer();
1440 alertpanel_error(_("Quote mark format error."));
1442 Xstrdup_a(quote_str, buf, return NULL)
1445 quote_fmt_init(msginfo, quote_str);
1446 quote_fmt_scan_string(fmt);
1449 buf = quote_fmt_get_buffer();
1451 alertpanel_error(_("Message reply/forward format error."));
1455 gtk_stext_freeze(text);
1456 gtk_stext_set_point(text, 0);
1457 gtk_stext_forward_delete(text, gtk_stext_get_length(text));
1459 for (p = buf; *p != '\0'; ) {
1460 lastp = strchr(p, '\n');
1461 len = lastp ? lastp - p + 1 : -1;
1462 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1469 gtk_stext_thaw(text);
1474 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1475 gboolean to_all, gboolean ignore_replyto,
1476 gboolean followup_and_reply_to)
1481 GHashTable *to_table;
1483 g_return_if_fail(compose->account != NULL);
1484 g_return_if_fail(msginfo != NULL);
1486 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1487 compose_entry_append(compose,
1488 ((compose->mailinglist && !ignore_replyto)
1489 ? compose->mailinglist
1490 : (compose->replyto && !ignore_replyto)
1492 : msginfo->from ? msginfo->from : ""),
1494 if (compose->account->protocol == A_NNTP)
1496 compose_entry_append(compose,
1497 msginfo->from ? msginfo->from : "",
1500 compose_entry_append(compose,
1501 compose->followup_to ? compose->followup_to
1502 : compose->newsgroups ? compose->newsgroups
1504 COMPOSE_NEWSGROUPS);
1506 compose_entry_append(compose,
1507 compose->followup_to ? compose->followup_to
1508 : compose->newsgroups ? compose->newsgroups
1510 COMPOSE_NEWSGROUPS);
1513 if (msginfo->subject && *msginfo->subject) {
1514 gchar *buf, *buf2, *p;
1516 buf = g_strdup(msginfo->subject);
1517 while (!strncasecmp(buf, "Re:", 3)) {
1519 while (isspace(*p)) p++;
1520 memmove(buf, p, strlen(p) + 1);
1523 buf2 = g_strdup_printf("Re: %s", buf);
1524 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1528 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1530 if (!to_all || compose->account->protocol == A_NNTP) return;
1532 from = g_strdup(compose->replyto ? compose->replyto :
1533 msginfo->from ? msginfo->from : "");
1534 extract_address(from);
1536 cc_list = address_list_append(NULL, msginfo->to);
1537 cc_list = address_list_append(cc_list, compose->cc);
1539 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1540 g_hash_table_insert(to_table, from, GINT_TO_POINTER(1));
1541 if (compose->account)
1542 g_hash_table_insert(to_table, compose->account->address,
1543 GINT_TO_POINTER(1));
1545 /* remove address on To: and that of current account */
1546 for (cur = cc_list; cur != NULL; ) {
1547 GSList *next = cur->next;
1549 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1550 cc_list = g_slist_remove(cc_list, cur->data);
1552 g_hash_table_insert(to_table, cur->data, cur);
1556 g_hash_table_destroy(to_table);
1560 for (cur = cc_list; cur != NULL; cur = cur->next)
1561 compose_entry_append(compose, (gchar *)cur->data,
1563 slist_free_strings(cc_list);
1564 g_slist_free(cc_list);
1568 #define SET_ENTRY(entry, str) \
1571 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1574 #define SET_ADDRESS(type, str) \
1577 compose_entry_append(compose, str, type); \
1580 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1582 g_return_if_fail(msginfo != NULL);
1584 SET_ENTRY(subject_entry, msginfo->subject);
1585 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1586 SET_ADDRESS(COMPOSE_CC, compose->cc);
1587 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1588 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1590 #if 0 /* NEW COMPOSE GUI */
1592 GtkItemFactory *ifactory;
1593 GtkWidget *menuitem;
1595 ifactory = gtk_item_factory_from_widget(compose->menubar);
1596 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
1597 gtk_check_menu_item_set_active
1598 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1600 if (compose->replyto) {
1601 GtkItemFactory *ifactory;
1602 GtkWidget *menuitem;
1604 ifactory = gtk_item_factory_from_widget(compose->menubar);
1605 menuitem = gtk_item_factory_get_item
1606 (ifactory, "/Message/Reply to");
1607 gtk_check_menu_item_set_active
1608 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1616 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1623 size_t buf_len = 128;
1625 if (strlen(sigfile) < 2)
1628 sigprg = popen(sigfile+1, "r");
1631 buf = g_malloc(buf_len);
1634 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1635 "Unable to insert signature (malloc failed)\n", -1);
1641 while (!feof(sigprg)) {
1642 bzero(buf, buf_len);
1643 fread(buf, buf_len-1, 1, sigprg);
1644 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1652 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1653 "Can't exec file: ", -1);
1654 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1659 static void compose_insert_sig(Compose *compose)
1663 if (compose->account && compose->account->sig_path)
1664 sigfile = g_strdup(compose->account->sig_path);
1666 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1667 DEFAULT_SIGNATURE, NULL);
1670 if (!is_file_or_fifo_exist(sigfile) & (sigfile[0] != '|')) {
1675 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1676 if (prefs_common.sig_sep) {
1677 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1678 prefs_common.sig_sep, -1);
1679 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1683 if (sigfile[0] == '|')
1685 compose_exec_sig(compose, sigfile);
1689 compose_insert_file(compose, sigfile);
1694 static void compose_insert_file(Compose *compose, const gchar *file)
1696 GtkSText *text = GTK_STEXT(compose->text);
1697 gchar buf[BUFFSIZE];
1701 g_return_if_fail(file != NULL);
1703 if ((fp = fopen(file, "r")) == NULL) {
1704 FILE_OP_ERROR(file, "fopen");
1708 gtk_stext_freeze(text);
1710 while (fgets(buf, sizeof(buf), fp) != NULL) {
1711 /* Strip <CR> if DOS/Windoze file, replace <CR> with <LF> if MAC file */
1713 if (len > 1 && buf[len - 2] == '\r' && buf[len - 1] == '\n') {
1714 buf[len - 2] = '\n';
1715 buf[len - 1] = '\0';
1718 if (buf[len] == '\r')
1722 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1725 gtk_stext_thaw(text);
1730 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
1731 ContentType cnttype)
1733 gchar *text[N_ATTACH_COLS];
1736 text[COL_MIMETYPE] = ainfo->content_type;
1737 text[COL_SIZE] = to_human_readable(ainfo->size);
1738 text[COL_NAME] = ainfo->name;
1740 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1741 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1743 if (cnttype != MIME_MESSAGE_RFC822)
1744 compose_changed_cb(NULL, compose);
1747 static void compose_attach_append_with_type(Compose *compose,
1750 ContentType cnttype)
1755 if (!is_file_exist(file)) {
1756 g_warning(_("File %s doesn't exist\n"), file);
1759 if ((size = get_file_size(file)) < 0) {
1760 g_warning(_("Can't get file size of %s\n"), file);
1764 alertpanel_notice(_("File %s is empty\n"), file);
1767 #if 0 /* NEW COMPOSE GUI */
1768 if (!compose->use_attach) {
1769 GtkItemFactory *ifactory;
1770 GtkWidget *menuitem;
1772 ifactory = gtk_item_factory_from_widget(compose->menubar);
1773 menuitem = gtk_item_factory_get_item(ifactory,
1775 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1779 ainfo = g_new0(AttachInfo, 1);
1780 ainfo->file = g_strdup(file);
1782 if (cnttype == MIME_MESSAGE_RFC822) {
1783 ainfo->encoding = ENC_7BIT;
1784 ainfo->name = g_strdup_printf(_("Message: %s"),
1787 ainfo->encoding = ENC_BASE64;
1788 ainfo->name = g_strdup(g_basename(file));
1791 ainfo->content_type = g_strdup(type);
1794 compose_attach_info(compose, ainfo, cnttype);
1797 static void compose_attach_append(Compose *compose, const gchar *file,
1798 ContentType cnttype)
1801 gchar *text[N_ATTACH_COLS];
1805 if (!is_file_exist(file)) {
1806 g_warning(_("File %s doesn't exist\n"), file);
1809 if ((size = get_file_size(file)) < 0) {
1810 g_warning(_("Can't get file size of %s\n"), file);
1814 alertpanel_notice(_("File %s is empty\n"), file);
1817 #if 0 /* NEW COMPOSE GUI */
1818 if (!compose->use_attach) {
1819 GtkItemFactory *ifactory;
1820 GtkWidget *menuitem;
1822 ifactory = gtk_item_factory_from_widget(compose->menubar);
1823 menuitem = gtk_item_factory_get_item(ifactory,
1825 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1829 ainfo = g_new0(AttachInfo, 1);
1830 ainfo->file = g_strdup(file);
1832 if (cnttype == MIME_MESSAGE_RFC822) {
1833 ainfo->content_type = g_strdup("message/rfc822");
1834 ainfo->encoding = ENC_7BIT;
1835 ainfo->name = g_strdup_printf(_("Message: %s"),
1838 ainfo->content_type = procmime_get_mime_type(file);
1839 if (!ainfo->content_type)
1840 ainfo->content_type =
1841 g_strdup("application/octet-stream");
1842 ainfo->encoding = ENC_BASE64;
1843 ainfo->name = g_strdup(g_basename(file));
1847 compose_attach_info(compose, ainfo, cnttype);
1850 static void compose_wrap_line(Compose *compose)
1852 GtkSText *text = GTK_STEXT(compose->text);
1853 gint ch_len, last_ch_len;
1854 gchar cbuf[MB_LEN_MAX], last_ch;
1858 gint p_start, p_end;
1859 gint line_pos, cur_pos;
1860 gint line_len, cur_len;
1862 #define GET_STEXT(pos) \
1863 if (text->use_wchar) \
1864 ch_len = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
1866 cbuf[0] = GTK_STEXT_INDEX(text, (pos)); \
1870 gtk_stext_freeze(text);
1872 text_len = gtk_stext_get_length(text);
1874 /* check to see if the point is on the paragraph mark (empty line). */
1875 cur_pos = gtk_stext_get_point(text);
1877 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
1879 goto compose_end; /* on the paragraph mark */
1880 GET_STEXT(cur_pos - 1);
1881 if (ch_len == 1 && *cbuf == '\n')
1882 goto compose_end; /* on the paragraph mark */
1885 /* find paragraph start. */
1886 line_end = quoted = 0;
1887 for (p_start = cur_pos; p_start >= 0; --p_start) {
1889 if (ch_len == 1 && *cbuf == '\n') {
1891 goto compose_end; /* quoted part */
1898 if (ch_len == 1 && strchr(">:#", *cbuf))
1900 else if (ch_len != 1 || !isspace(*cbuf))
1909 /* find paragraph end. */
1911 for (p_end = cur_pos; p_end < text_len; p_end++) {
1913 if (ch_len == 1 && *cbuf == '\n') {
1920 if (line_end && ch_len == 1 && strchr(">:#", *cbuf))
1921 goto compose_end; /* quoted part */
1926 if (p_end >= text_len)
1929 if (p_start >= p_end)
1932 line_len = cur_len = 0;
1936 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
1946 if (ch_len == 1 && isspace(*cbuf))
1949 if (ch_len == 1 && *cbuf == '\n') {
1951 if (last_ch_len == 1 && !isspace(last_ch)) {
1952 if (cur_pos + 1 < p_end) {
1953 GET_STEXT(cur_pos + 1);
1954 if (ch_len == 1 && !isspace(*cbuf))
1958 gtk_stext_set_point(text, cur_pos + 1);
1959 gtk_stext_backward_delete(text, 1);
1961 gtk_stext_set_point(text, cur_pos);
1962 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
1972 last_ch_len = ch_len;
1976 line_pos = cur_pos + 1;
1977 line_len = cur_len + ch_len;
1980 if (cur_len + ch_len > prefs_common.linewrap_len &&
1984 GET_STEXT(line_pos - 1);
1985 if (ch_len == 1 && isspace(*cbuf)) {
1986 gtk_stext_set_point(text, line_pos);
1987 gtk_stext_backward_delete(text, 1);
1996 gtk_stext_set_point(text, line_pos);
1997 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2001 cur_len = cur_len - line_len + ch_len;
2007 line_pos = cur_pos + 1;
2008 line_len = cur_len + ch_len;
2014 gtk_stext_thaw(text);
2019 /* return indent length */
2020 static guint get_indent_length(GtkSText *text, guint start_pos,
2022 gint indent_len = 0;
2024 gchar cbuf[MB_CUR_MAX];
2026 for (i = start_pos; i < text_len; i++) {
2027 if (text->use_wchar)
2029 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, i));
2031 cbuf[0] = GTK_STEXT_INDEX(text, i);
2036 /* allow space, tab, > or | */
2037 if (cbuf[0] != ' ' && cbuf[0] != '\t' &&
2038 cbuf[0] != '>' && cbuf[0] != '|')
2046 /* insert quotation string when line was wrapped, we know these
2047 are single byte characters */
2048 static guint ins_quote(GtkSText *text, guint quote_len, guint indent_len,
2049 guint prev_line_pos, guint text_len,
2055 for (i = 0; i < indent_len; i++) {
2056 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2057 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2059 ins_len = indent_len;
2062 gtk_stext_insert(text, NULL, NULL, NULL, quote_fmt, quote_len);
2063 ins_len = quote_len;
2071 /* Darko: used when I debug wrapping */
2072 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2077 printf("%d [", pos);
2078 for (i = pos; i < tlen; i++)
2080 ch = GTK_STEXT_INDEX(text, i);
2081 if (breakoncr && ch == '\n')
2089 static void compose_wrap_line_all(Compose *compose)
2091 GtkSText *text = GTK_STEXT(compose->text);
2093 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2094 gint line_len = 0, cur_len = 0;
2096 gint is_new_line = 1, do_delete = 0;
2097 guint qlen = 0, i_len = 0;
2098 guint linewrap_quote = prefs_common.linewrap_quote;
2099 guint linewrap_len = prefs_common.linewrap_len;
2100 gchar *qfmt = prefs_common.quotemark;
2101 gchar cbuf[MB_LEN_MAX];
2103 gtk_stext_freeze(text);
2105 /* make text buffer contiguous */
2106 gtk_stext_compact_buffer(text);
2108 tlen = gtk_stext_get_length(text);
2110 for (; cur_pos < tlen; cur_pos++) {
2111 /* mark position of new line - needed for quotation wrap */
2112 if (linewrap_quote && is_new_line) {
2113 qlen = gtkstext_str_strcmp(text, cur_pos, tlen, qfmt);
2116 i_len = get_indent_length(text, cur_pos, tlen);
2122 printf("new line i_len=%d qlen=%d p_pos=", i_len, qlen);
2123 dump_text(text, p_pos, tlen, 1);
2127 /* get character(s) at current position */
2128 if (text->use_wchar)
2130 (cbuf, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
2132 cbuf[0] = GTK_STEXT_INDEX(text, cur_pos);
2136 /* fix line length for tabs */
2137 if (ch_len == 1 && *cbuf == '\t') {
2138 guint tab_width = text->default_tab_width;
2139 guint tab_offset = line_len % tab_width;
2142 printf("found tab at pos=%d line_len=%d ", cur_pos,
2146 line_len += tab_width - tab_offset - 1;
2150 printf("new_len=%d\n", line_len);
2154 /* we have encountered line break */
2155 if (ch_len == 1 && *cbuf == '\n') {
2158 gchar cb[MB_CUR_MAX];
2161 printf("found CR at %d\n", cur_pos);
2163 /* if it's just quotation + newline skip it */
2164 if (i_len && (cur_pos + 1 < tlen)) {
2165 /* check if text at new line matches indent */
2166 ilen = gtkstext_strncmp(text, cur_pos + 1,
2167 p_pos, i_len, tlen);
2168 if (cur_pos + ilen < tlen) {
2169 if (text->use_wchar)
2170 clen = wctomb(cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos + ilen + 1));
2172 cb[0] = GTK_STEXT_INDEX(text,
2173 cur_pos + ilen + 1);
2176 /* no need to join the lines */
2177 if ((clen == 1) && (cb[0] == '\n'))
2183 printf("qlen=%d l_len=%d wrap_len=%d do_del=%d\n",
2184 qlen, line_len, linewrap_len, do_delete);
2186 /* should we delete to perform smart wrapping */
2187 if (qlen && line_len < linewrap_len && do_delete) {
2188 /* get rid of newline */
2189 gtk_stext_set_point(text, cur_pos);
2190 gtk_stext_forward_delete(text, 1);
2193 /* if text starts with quote fmt or with
2194 indent string, delete them */
2196 ilen = gtkstext_strncmp(text, cur_pos,
2200 gtk_stext_forward_delete(text,
2206 if (gtkstext_str_strcmp(text, cur_pos,
2208 gtk_stext_forward_delete(text,
2214 if (text->use_wchar)
2216 (cb, (wchar_t)GTK_STEXT_INDEX(text, cur_pos));
2218 cb[0] = GTK_STEXT_INDEX(text, cur_pos);
2222 /* insert space if it's alphanumeric */
2223 if ((cur_pos != line_pos) &&
2224 ((clen > 1) || isalnum(cb[0]))) {
2225 gtk_stext_insert(text, NULL, NULL,
2227 gtk_stext_compact_buffer(text);
2231 /* and start over with current line */
2232 cur_pos = p_pos - 1;
2234 line_len = cur_len = 0;
2239 printf("after delete l_pos=");
2240 dump_text(text, line_pos, tlen, 1);
2245 /* mark new line beginning */
2246 line_pos = cur_pos + 1;
2247 line_len = cur_len = 0;
2259 /* possible line break */
2260 if (ch_len == 1 && isspace(*cbuf)) {
2261 line_pos = cur_pos + 1;
2262 line_len = cur_len + ch_len;
2265 /* are we over wrapping length set in preferences ? */
2266 if (cur_len + ch_len > linewrap_len) {
2270 printf("should wrap cur_pos=%d ", cur_pos);
2271 dump_text(text, p_pos, tlen, 1);
2272 dump_text(text, line_pos, tlen, 1);
2274 /* force wrapping if it is one long word but not URL */
2275 if (p_pos + i_len == line_pos)
2276 if (!is_url_string(text, line_pos, tlen))
2277 line_pos = cur_pos - 1;
2279 printf("new line_pos=%d\n", line_pos);
2282 /* if next character is space delete it */
2283 if (text->use_wchar)
2284 clen = wctomb(cbuf, (wchar_t)GTK_STEXT_INDEX(text, line_pos - 1));
2286 cbuf[0] = GTK_STEXT_INDEX(text, line_pos - 1);
2289 if (clen == 1 && isspace(*cbuf)) {
2290 if (p_pos + i_len != line_pos ||
2291 !is_url_string(text, line_pos, tlen)) {
2292 gtk_stext_set_point(text, line_pos);
2293 gtk_stext_backward_delete(text, 1);
2302 /* if it is URL at beginning of line don't wrap */
2303 if (p_pos + i_len == line_pos &&
2304 is_url_string(text, line_pos, tlen)) {
2306 printf("found URL at ");
2307 dump_text(text, line_pos, tlen, 1);
2313 gtk_stext_set_point(text, line_pos);
2314 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2315 gtk_stext_compact_buffer(text);
2319 cur_len = cur_len - line_len + ch_len;
2322 printf("after CR insert ");
2323 dump_text(text, line_pos, tlen, 1);
2326 /* should we insert quotation ? */
2327 if (linewrap_quote && qlen) {
2328 /* only if line is not already quoted */
2329 if (!gtkstext_str_strcmp(text, line_pos,
2333 if (line_pos - p_pos > i_len) {
2334 ins_len = ins_quote(text,
2341 gtk_stext_compact_buffer(text);
2345 /* for loop will increase it */
2346 cur_pos = line_pos - 1;
2349 /* start over with current line */
2353 printf("after quote insert ");
2354 dump_text(text, line_pos, tlen, 1);
2362 line_pos = cur_pos + 1;
2363 line_len = cur_len + ch_len;
2365 /* advance to next character in buffer */
2369 gtk_stext_thaw(text);
2372 static void compose_set_title(Compose *compose)
2377 edited = compose->modified ? _(" [Edited]") : "";
2378 if (compose->account && compose->account->address)
2379 str = g_strdup_printf(_("%s - Compose message%s"),
2380 compose->account->address, edited);
2382 str = g_strdup_printf(_("Compose message%s"), edited);
2383 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2388 * compose_current_mail_account:
2390 * Find a current mail account (the currently selected account, or the
2391 * default account, if a news account is currently selected). If a
2392 * mail account cannot be found, display an error message.
2394 * Return value: Mail account, or NULL if not found.
2396 static PrefsAccount *
2397 compose_current_mail_account(void)
2401 if (cur_account && cur_account->protocol != A_NNTP)
2404 ac = account_get_default();
2405 if (!ac || ac->protocol == A_NNTP) {
2406 alertpanel_error(_("Account for sending mail is not specified.\n"
2407 "Please select a mail account before sending."));
2414 gboolean compose_check_for_valid_recipient(Compose *compose) {
2415 gchar *recipient_headers[] = {"To:", "Newsgroups:", "Cc:", "Bcc:", NULL};
2416 gboolean recipient_found = FALSE;
2420 for(list = compose->header_list; list; list = list->next) {
2423 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((compose_headerentry *)list->data)->combo)->entry));
2424 entry = gtk_editable_get_chars(GTK_EDITABLE(((compose_headerentry *)list->data)->entry), 0, -1);
2426 if(entry[0] != '\0') {
2427 for(strptr = recipient_headers; *strptr != NULL; strptr++) {
2428 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2429 recipient_found = TRUE;
2435 return recipient_found;
2438 gint compose_send(Compose *compose)
2440 gchar tmp[MAXPATHLEN + 1];
2442 static gboolean lock = FALSE;
2446 g_return_val_if_fail(compose->account != NULL, -1);
2447 g_return_val_if_fail(compose->orig_account != NULL, -1);
2451 if(!compose_check_for_valid_recipient(compose)) {
2452 alertpanel_error(_("Recipient is not specified."));
2457 /* write to temporary file */
2458 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2459 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2461 if (prefs_common.linewrap_at_send)
2462 compose_wrap_line_all(compose);
2464 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2469 if (!compose->to_list && !compose->newsgroup_list) {
2470 g_warning(_("can't get recipient list."));
2476 if (compose->to_list) {
2479 #if 0 /* NEW COMPOSE GUI */
2480 if (compose->account->protocol != A_NNTP)
2481 ac = compose->account;
2482 else if (compose->orig_account->protocol != A_NNTP)
2483 ac = compose->orig_account;
2484 else if (cur_account && cur_account->protocol != A_NNTP)
2487 ac = compose_current_mail_account();
2495 ac = compose->account;
2497 ok = send_message(tmp, ac, compose->to_list);
2498 statusbar_pop_all();
2501 if (ok == 0 && compose->newsgroup_list) {
2504 if (compose->account->protocol == A_NNTP)
2505 folder = FOLDER(compose->account->folder);
2507 folder = FOLDER(compose->orig_account->folder);
2509 ok = news_post(folder, tmp);
2511 alertpanel_error(_("Error occurred while posting the message to %s ."),
2512 compose->account->nntp_server);
2519 /* queue message if failed to send */
2521 if (prefs_common.queue_msg) {
2526 _("Error occurred while sending the message.\n"
2527 "Put this message into queue folder?"),
2528 _("OK"), _("Cancel"), NULL);
2529 if (G_ALERTDEFAULT == val) {
2530 ok = compose_queue(compose, tmp);
2532 alertpanel_error(_("Can't queue the message."));
2535 alertpanel_error(_("Error occurred while sending the message."));
2537 if (compose->mode == COMPOSE_REEDIT) {
2538 compose_remove_reedit_target(compose);
2539 if (compose->targetinfo)
2540 folderview_update_item
2541 (compose->targetinfo->folder, TRUE);
2545 /* save message to outbox */
2546 if (ok == 0 && prefs_common.savemsg) {
2547 if (compose_save_to_outbox(compose, tmp) < 0)
2549 (_("Can't save the message to outbox."));
2557 static gboolean compose_use_attach(Compose *compose) {
2558 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2561 static gint compose_write_to_file(Compose *compose, const gchar *file,
2568 const gchar *out_codeset;
2569 EncodingType encoding;
2571 if ((fp = fopen(file, "w")) == NULL) {
2572 FILE_OP_ERROR(file, "fopen");
2576 /* chmod for security */
2577 if (change_file_mode_rw(fp, file) < 0) {
2578 FILE_OP_ERROR(file, "chmod");
2579 g_warning(_("can't change file mode\n"));
2582 /* get all composed text */
2583 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2584 len = strlen(chars);
2585 if (is_ascii_str(chars)) {
2586 buf = g_strdup(chars);
2587 out_codeset = CS_US_ASCII;
2588 encoding = ENC_7BIT;
2590 const gchar *src_codeset;
2592 out_codeset = conv_get_outgoing_charset_str();
2593 if (!strcasecmp(out_codeset, CS_US_ASCII))
2594 out_codeset = CS_ISO_8859_1;
2595 encoding = procmime_get_encoding_for_charset(out_codeset);
2597 src_codeset = conv_get_current_charset_str();
2598 /* if current encoding is US-ASCII, set it the same as
2599 outgoing one to prevent code conversion failure */
2600 if (!strcasecmp(src_codeset, CS_US_ASCII))
2601 src_codeset = out_codeset;
2603 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
2604 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
2606 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
2611 alertpanel_error(_("Can't convert the codeset of the message."));
2618 if (compose_write_headers
2619 (compose, fp, out_codeset, encoding, is_draft) < 0) {
2620 g_warning(_("can't write headers\n"));
2627 if (compose_use_attach(compose)) {
2629 /* This prolog message is ignored by mime software and
2630 * because it would make our signing/encryption task
2631 * tougher, we don't emit it in that case */
2632 if (!compose->use_signing && !compose->use_encryption)
2634 fputs("This is a multi-part message in MIME format.\n", fp);
2636 fprintf(fp, "\n--%s\n", compose->boundary);
2637 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
2639 fprintf(fp, "Content-Transfer-Encoding: %s\n",
2640 procmime_get_encoding_str(encoding));
2646 if (encoding == ENC_BASE64) {
2647 gchar outbuf[B64_BUFFSIZE];
2650 for (i = 0; i < len; i += B64_LINE_SIZE) {
2651 l = MIN(B64_LINE_SIZE, len - i);
2652 to64frombits(outbuf, buf + i, l);
2656 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
2657 FILE_OP_ERROR(file, "fwrite");
2665 if (compose_use_attach(compose))
2666 compose_write_attach(compose, fp);
2668 if (fclose(fp) == EOF) {
2669 FILE_OP_ERROR(file, "fclose");
2675 if (compose->use_signing) {
2676 if (rfc2015_sign(file, compose->account) < 0) {
2681 if (compose->use_encryption) {
2682 if (rfc2015_encrypt(file, compose->to_list) < 0) {
2687 #endif /* USE_GPGME */
2692 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
2698 if ((fp = fopen(file, "w")) == NULL) {
2699 FILE_OP_ERROR(file, "fopen");
2703 /* chmod for security */
2704 if (change_file_mode_rw(fp, file) < 0) {
2705 FILE_OP_ERROR(file, "chmod");
2706 g_warning(_("can't change file mode\n"));
2709 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
2712 len = strlen(chars);
2713 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
2714 FILE_OP_ERROR(file, "fwrite");
2723 if (fclose(fp) == EOF) {
2724 FILE_OP_ERROR(file, "fclose");
2731 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
2738 debug_print(_("saving sent message...\n"));
2740 outbox = folder_get_default_outbox();
2741 path = folder_item_get_path(outbox);
2742 if (!is_dir_exist(path))
2743 make_dir_hier(path);
2745 folder_item_scan(outbox);
2746 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
2748 g_warning(_("can't save message\n"));
2752 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
2753 g_warning(_("can't open mark file\n"));
2757 newmsginfo.msgnum = num;
2758 newmsginfo.flags.perm_flags = 0;
2759 newmsginfo.flags.tmp_flags = 0;
2760 procmsg_write_flags(&newmsginfo, fp);
2768 static gint compose_remove_reedit_target(Compose *compose)
2771 MsgInfo *msginfo = compose->targetinfo;
2773 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
2774 if (!msginfo) return -1;
2776 item = msginfo->folder;
2777 g_return_val_if_fail(item != NULL, -1);
2779 folder_item_scan(item);
2780 if (procmsg_msg_exist(msginfo) &&
2781 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
2782 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
2783 g_warning(_("can't remove the old message\n"));
2791 static gint compose_queue(Compose *compose, const gchar *file)
2794 gchar *tmp, *queue_path;
2797 gchar buf[BUFFSIZE];
2800 debug_print(_("queueing message...\n"));
2801 g_return_val_if_fail(compose->to_list != NULL, -1);
2802 g_return_val_if_fail(compose->account != NULL, -1);
2804 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
2805 G_DIR_SEPARATOR, (gint)compose);
2806 if ((fp = fopen(tmp, "w")) == NULL) {
2807 FILE_OP_ERROR(tmp, "fopen");
2811 if ((src_fp = fopen(file, "r")) == NULL) {
2812 FILE_OP_ERROR(file, "fopen");
2818 if (change_file_mode_rw(fp, tmp) < 0) {
2819 FILE_OP_ERROR(tmp, "chmod");
2820 g_warning(_("can't change file mode\n"));
2823 /* queueing variables */
2824 fprintf(fp, "AF:\n");
2825 fprintf(fp, "NF:0\n");
2826 fprintf(fp, "PS:10\n");
2827 fprintf(fp, "SRH:1\n");
2828 fprintf(fp, "SFN:\n");
2829 fprintf(fp, "DSR:\n");
2831 fprintf(fp, "MID:<%s>\n", compose->msgid);
2833 fprintf(fp, "MID:\n");
2834 fprintf(fp, "CFG:\n");
2835 fprintf(fp, "PT:0\n");
2836 fprintf(fp, "S:%s\n", compose->account->address);
2837 fprintf(fp, "RQ:\n");
2838 if (compose->account->smtp_server)
2839 fprintf(fp, "SSV:%s\n", compose->account->smtp_server);
2841 fprintf(fp, "SSV:\n");
2842 if (compose->account->nntp_server)
2843 fprintf(fp, "NSV:%s\n", compose->account->nntp_server);
2845 fprintf(fp, "NSV:\n");
2846 fprintf(fp, "SSH:\n");
2847 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
2848 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
2849 fprintf(fp, ",<%s>", (gchar *)cur->data);
2851 /* Sylpheed account ID */
2852 fprintf(fp, "AID:%d\n", compose->account->account_id);
2855 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
2856 if (fputs(buf, fp) == EOF) {
2857 FILE_OP_ERROR(tmp, "fputs");
2867 if (fclose(fp) == EOF) {
2868 FILE_OP_ERROR(tmp, "fclose");
2874 queue = folder_get_default_queue();
2876 folder_item_scan(queue);
2877 queue_path = folder_item_get_path(queue);
2878 if (!is_dir_exist(queue_path))
2879 make_dir_hier(queue_path);
2880 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
2881 g_warning(_("can't queue the message\n"));
2889 if (compose->mode == COMPOSE_REEDIT) {
2890 compose_remove_reedit_target(compose);
2891 if (compose->targetinfo &&
2892 compose->targetinfo->folder != queue)
2893 folderview_update_item
2894 (compose->targetinfo->folder, TRUE);
2897 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
2898 g_warning(_("can't open mark file\n"));
2902 newmsginfo.msgnum = num;
2903 newmsginfo.flags.perm_flags = 0;
2904 newmsginfo.flags.tmp_flags = 0;
2905 procmsg_write_flags(&newmsginfo, fp);
2910 folder_item_scan(queue);
2911 folderview_update_item(queue, TRUE);
2916 static void compose_write_attach(Compose *compose, FILE *fp)
2919 GtkCList *clist = GTK_CLIST(compose->attach_clist);
2922 gchar filename[BUFFSIZE];
2925 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
2927 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
2928 g_warning(_("Can't open file %s\n"), ainfo->file);
2932 fprintf(fp, "\n--%s\n", compose->boundary);
2934 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
2935 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
2936 fprintf(fp, "Content-Disposition: inline\n");
2938 conv_encode_header(filename, sizeof(filename),
2940 fprintf(fp, "Content-Type: %s;\n"
2942 ainfo->content_type, filename);
2943 fprintf(fp, "Content-Disposition: attachment;\n"
2944 " filename=\"%s\"\n", filename);
2947 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
2948 procmime_get_encoding_str(ainfo->encoding));
2950 if (ainfo->encoding == ENC_7BIT) {
2951 gchar buf[BUFFSIZE];
2953 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
2958 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
2960 while ((len = fread(inbuf, sizeof(gchar),
2961 B64_LINE_SIZE, attach_fp))
2963 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
2967 if (len > 0 && feof(attach_fp)) {
2968 to64frombits(outbuf, inbuf, len);
2977 fprintf(fp, "\n--%s--\n", compose->boundary);
2980 #define IS_IN_CUSTOM_HEADER(header) \
2981 (compose->account->add_customhdr && \
2982 custom_header_find(compose->account->customhdr_list, header) != NULL)
2984 static gint compose_write_headers_from_headerlist(Compose *compose,
2987 GSList *(*list_append_func) (GSList *list, const gchar *str),
2990 gchar buf[BUFFSIZE];
2991 gchar *str, *header_w_colon, *trans_hdr;
2992 gboolean first_address;
2994 compose_headerentry *headerentry;
2996 if (IS_IN_CUSTOM_HEADER(header)) {
3000 debug_print(_("Writing %s-header\n"), header);
3002 header_w_colon = g_strconcat(header, ":", NULL);
3003 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3005 first_address = TRUE;
3006 for(list = compose->header_list; list; list = list->next) {
3007 headerentry = ((compose_headerentry *)list->data);
3008 if(!strcmp(trans_hdr, gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)))) {
3009 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3010 Xstrdup_a(str, str, return -1);
3012 if(str[0] != '\0') {
3013 if(list_append_func)
3014 *dest_list = list_append_func(*dest_list, str);
3015 compose_convert_header
3016 (buf, sizeof(buf), str,
3017 strlen(header) + 2);
3019 fprintf(fp, "%s: ", header);
3020 first_address = FALSE;
3024 fprintf(fp, "%s", buf);
3028 if(!first_address) {
3032 g_free(header_w_colon);
3037 static gint compose_write_headers(Compose *compose, FILE *fp,
3038 const gchar *charset, EncodingType encoding,
3041 gchar buf[BUFFSIZE];
3043 /* struct utsname utsbuf; */
3045 g_return_val_if_fail(fp != NULL, -1);
3046 g_return_val_if_fail(charset != NULL, -1);
3047 g_return_val_if_fail(compose->account != NULL, -1);
3048 g_return_val_if_fail(compose->account->address != NULL, -1);
3051 if (compose->account->add_date) {
3052 get_rfc822_date(buf, sizeof(buf));
3053 fprintf(fp, "Date: %s\n", buf);
3057 if (!IS_IN_CUSTOM_HEADER("From")) {
3058 if (compose->account->name && *compose->account->name) {
3059 compose_convert_header
3060 (buf, sizeof(buf), compose->account->name,
3062 fprintf(fp, "From: %s <%s>\n",
3063 buf, compose->account->address);
3065 fprintf(fp, "From: %s\n", compose->account->address);
3068 slist_free_strings(compose->to_list);
3069 g_slist_free(compose->to_list);
3070 compose->to_list = NULL;
3073 compose_write_headers_from_headerlist(compose, fp, "To", address_list_append, &compose->to_list);
3074 #if 0 /* NEW COMPOSE GUI */
3075 if (compose->use_to) {
3076 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3078 Xstrdup_a(str, str, return -1);
3081 compose->to_list = address_list_append
3082 (compose->to_list, str);
3083 if (!IS_IN_CUSTOM_HEADER("To")) {
3084 compose_convert_header
3085 (buf, sizeof(buf), str,
3087 fprintf(fp, "To: %s\n", buf);
3093 slist_free_strings(compose->newsgroup_list);
3094 g_slist_free(compose->newsgroup_list);
3095 compose->newsgroup_list = NULL;
3098 compose_write_headers_from_headerlist(compose, fp, "Newsgroups", newsgroup_list_append, &compose->newsgroup_list);
3099 #if 0 /* NEW COMPOSE GUI */
3100 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3102 Xstrdup_a(str, str, return -1);
3106 compose->newsgroup_list =
3107 newsgroup_list_append(compose->newsgroup_list,
3109 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
3110 compose_convert_header(buf, sizeof(buf), str,
3111 strlen("Newsgroups: "));
3112 fprintf(fp, "Newsgroups: %s\n", buf);
3118 compose_write_headers_from_headerlist(compose, fp, "Cc", address_list_append, &compose->to_list);
3119 #if 0 /* NEW COMPOSE GUI */
3120 if (compose->use_cc) {
3121 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3123 Xstrdup_a(str, str, return -1);
3126 compose->to_list = address_list_append
3127 (compose->to_list, str);
3128 if (!IS_IN_CUSTOM_HEADER("Cc")) {
3129 compose_convert_header
3130 (buf, sizeof(buf), str,
3132 fprintf(fp, "Cc: %s\n", buf);
3139 compose_write_headers_from_headerlist(compose, fp, "Bcc", address_list_append, &compose->to_list);
3140 #if 0 /* NEW COMPOSE GUI */
3141 if (compose->use_bcc) {
3142 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3144 Xstrdup_a(str, str, return -1);
3147 compose->to_list = address_list_append
3148 (compose->to_list, str);
3149 compose_convert_header(buf, sizeof(buf), str,
3151 fprintf(fp, "Bcc: %s\n", buf);
3156 if (!is_draft && !compose->to_list && !compose->newsgroup_list)
3160 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3161 if (*str != '\0' && !IS_IN_CUSTOM_HEADER("Subject")) {
3162 Xstrdup_a(str, str, return -1);
3165 compose_convert_header(buf, sizeof(buf), str,
3166 strlen("Subject: "));
3167 fprintf(fp, "Subject: %s\n", buf);
3172 if (compose->account->gen_msgid) {
3173 compose_generate_msgid(compose, buf, sizeof(buf));
3174 fprintf(fp, "Message-Id: <%s>\n", buf);
3175 compose->msgid = g_strdup(buf);
3179 if (compose->inreplyto && compose->to_list)
3180 fprintf(fp, "In-Reply-To: <%s>\n", compose->inreplyto);
3183 if (compose->references)
3184 fprintf(fp, "References: %s\n", compose->references);
3187 compose_write_headers_from_headerlist(compose, fp, "Followup-To", NULL, NULL);
3188 #if 0 /* NEW COMPOSE GUI */
3189 if (compose->use_followupto && !IS_IN_CUSTOM_HEADER("Followup-To")) {
3190 str = gtk_entry_get_text(GTK_ENTRY(compose->followup_entry));
3192 Xstrdup_a(str, str, return -1);
3196 compose_convert_header(buf, sizeof(buf), str,
3197 strlen("Followup-To: "));
3198 fprintf(fp, "Followup-To: %s\n", buf);
3204 compose_write_headers_from_headerlist(compose, fp, "Reply-To", NULL, NULL);
3205 #if 0 /* NEW COMPOSE GUI */
3206 if (compose->use_replyto && !IS_IN_CUSTOM_HEADER("Reply-To")) {
3207 str = gtk_entry_get_text(GTK_ENTRY(compose->reply_entry));
3209 Xstrdup_a(str, str, return -1);
3212 compose_convert_header(buf, sizeof(buf), str,
3213 strlen("Reply-To: "));
3214 fprintf(fp, "Reply-To: %s\n", buf);
3220 if (compose->account->organization &&
3221 !IS_IN_CUSTOM_HEADER("Organization")) {
3222 compose_convert_header(buf, sizeof(buf),
3223 compose->account->organization,
3224 strlen("Organization: "));
3225 fprintf(fp, "Organization: %s\n", buf);
3228 /* Program version and system info */
3229 /* uname(&utsbuf); */
3230 if (g_slist_length(compose->to_list) && !IS_IN_CUSTOM_HEADER("X-Mailer")) {
3231 fprintf(fp, "X-Mailer: %s (GTK+ %d.%d.%d; %s)\n",
3233 gtk_major_version, gtk_minor_version, gtk_micro_version,
3235 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3237 if (g_slist_length(compose->newsgroup_list) && !IS_IN_CUSTOM_HEADER("X-Newsreader")) {
3238 fprintf(fp, "X-Newsreader: %s (GTK+ %d.%d.%d; %s)\n",
3240 gtk_major_version, gtk_minor_version, gtk_micro_version,
3242 /* utsbuf.sysname, utsbuf.release, utsbuf.machine); */
3245 /* custom headers */
3246 if (compose->account->add_customhdr) {
3249 for (cur = compose->account->customhdr_list; cur != NULL;
3251 CustomHeader *chdr = (CustomHeader *)cur->data;
3253 if (strcasecmp(chdr->name, "Date") != 0 &&
3254 strcasecmp(chdr->name, "From") != 0 &&
3255 strcasecmp(chdr->name, "To") != 0 &&
3256 strcasecmp(chdr->name, "Sender") != 0 &&
3257 strcasecmp(chdr->name, "Message-Id") != 0 &&
3258 strcasecmp(chdr->name, "In-Reply-To") != 0 &&
3259 strcasecmp(chdr->name, "References") != 0 &&
3260 strcasecmp(chdr->name, "Mime-Version") != 0 &&
3261 strcasecmp(chdr->name, "Content-Type") != 0 &&
3262 strcasecmp(chdr->name, "Content-Transfer-Encoding") != 0)
3263 compose_convert_header
3265 chdr->value ? chdr->value : "",
3266 strlen(chdr->name) + 2);
3267 fprintf(fp, "%s: %s\n", chdr->name, buf);
3272 fprintf(fp, "Mime-Version: 1.0\n");
3273 if (compose_use_attach(compose)) {
3274 get_rfc822_date(buf, sizeof(buf));
3275 subst_char(buf, ' ', '_');
3276 subst_char(buf, ',', '_');
3277 compose->boundary = g_strdup_printf("Multipart_%s_%08x",
3278 buf, (guint)compose);
3280 "Content-Type: multipart/mixed;\n"
3281 " boundary=\"%s\"\n", compose->boundary);
3283 fprintf(fp, "Content-Type: text/plain; charset=%s\n", charset);
3284 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3285 procmime_get_encoding_str(encoding));
3288 /* Request Return Receipt */
3289 if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
3290 if (compose->return_receipt) {
3291 if (compose->account->name
3292 && *compose->account->name) {
3293 compose_convert_header(buf, sizeof(buf), compose->account->name, strlen("Disposition-Notification-To: "));
3294 fprintf(fp, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
3296 fprintf(fp, "Disposition-Notification-To: %s\n", compose->account->address);
3300 /* separator between header and body */
3306 #undef IS_IN_CUSTOM_HEADER
3308 static void compose_convert_header(gchar *dest, gint len, gchar *src,
3311 g_return_if_fail(src != NULL);
3312 g_return_if_fail(dest != NULL);
3314 if (len < 1) return;
3318 if (is_ascii_str(src)) {
3319 strncpy2(dest, src, len);
3320 dest[len - 1] = '\0';
3323 conv_encode_header(dest, len, src, header_len);
3326 static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
3335 if (compose->account && compose->account->address &&
3336 *compose->account->address) {
3337 if (strchr(compose->account->address, '@'))
3338 addr = g_strdup(compose->account->address);
3340 addr = g_strconcat(compose->account->address, "@",
3341 get_domain_name(), NULL);
3343 addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
3346 g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
3347 lt->tm_year + 1900, lt->tm_mon + 1,
3348 lt->tm_mday, lt->tm_hour,
3349 lt->tm_min, lt->tm_sec,
3350 (guint)random(), addr);
3352 debug_print(_("generated Message-ID: %s\n"), buf);
3358 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
3359 GtkWidget **entry, gint *count,
3360 const gchar *label_str,
3361 gboolean is_addr_entry)
3365 if (GTK_TABLE(table)->nrows < (*count) + 1)
3366 gtk_table_resize(GTK_TABLE(table), (*count) + 1, 2);
3368 *hbox = gtk_hbox_new(FALSE, 0);
3369 label = gtk_label_new
3370 (prefs_common.trans_hdr ? gettext(label_str) : label_str);
3371 gtk_box_pack_end(GTK_BOX(*hbox), label, FALSE, FALSE, 0);
3372 gtk_table_attach(GTK_TABLE(table), *hbox, 0, 1, *count, (*count) + 1,
3374 *entry = gtk_entry_new();
3376 (GTK_TABLE(table), *entry, 1, 2, *count, (*count) + 1, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
3377 #if 0 /* NEW COMPOSE GUI */
3378 if (GTK_TABLE(table)->nrows > (*count) + 1)
3379 gtk_table_set_row_spacing(GTK_TABLE(table), *count, 4);
3383 address_completion_register_entry(GTK_ENTRY(*entry));
3388 static void compose_create_header_entry(Compose *compose) {
3389 gchar *headers[] = {"To:", "Cc:", "Bcc:", "Newsgroups:", "Reply-To:", "Followup-To:", NULL};
3393 GList *combo_list = NULL;
3394 gchar **string, *header;
3395 compose_headerentry *headerentry = g_new0(compose_headerentry, 1);
3398 combo = gtk_combo_new();
3400 while(*string != NULL) {
3401 combo_list = g_list_append(combo_list, (prefs_common.trans_hdr ? gettext(*string) : *string));
3404 gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
3405 g_list_free(combo_list);
3406 gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), FALSE);
3407 gtk_widget_show(combo);
3408 gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1, compose->header_nextrow, compose->header_nextrow+1, GTK_SHRINK, GTK_FILL, 0, 0);
3409 if(compose->header_last) {
3410 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
3412 switch(compose->account->protocol) {
3414 header = _("Newsgroups:");
3421 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
3424 entry = gtk_entry_new();
3425 gtk_widget_show(entry);
3426 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);
3428 gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
3429 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
3431 address_completion_register_entry(GTK_ENTRY(entry));
3433 headerentry->compose = compose;
3434 headerentry->combo = combo;
3435 headerentry->entry = entry;
3436 headerentry->headernum = compose->header_nextrow;
3438 compose->header_nextrow++;
3439 compose->header_last = headerentry;
3442 static void compose_add_header_entry(Compose *compose, gchar *header, gchar *text) {
3443 compose_headerentry *last_header;
3445 last_header = compose->header_last;
3447 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
3448 gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
3451 static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
3457 GtkWidget *handlebox;
3459 GtkWidget *notebook;
3463 GtkWidget *table_vbox;
3465 GtkWidget *from_optmenu_hbox;
3466 #if 0 /* NEW COMPOSE GUI */
3467 GtkWidget *to_entry;
3469 GtkWidget *newsgroups_entry;
3470 GtkWidget *newsgroups_hbox;
3472 GtkWidget *header_scrolledwin;
3473 GtkWidget *header_table;
3474 GtkWidget *subject_entry;
3475 #if 0 /* NEW COMPOSE GUI */
3476 GtkWidget *cc_entry;
3478 GtkWidget *bcc_entry;
3479 GtkWidget *bcc_hbox;
3480 GtkWidget *reply_entry;
3481 GtkWidget *reply_hbox;
3482 GtkWidget *followup_entry;
3483 GtkWidget *followup_hbox;
3487 GtkWidget *attach_scrwin;
3488 GtkWidget *attach_clist;
3490 GtkWidget *edit_vbox;
3491 GtkWidget *ruler_hbox;
3493 GtkWidget *scrolledwin;
3499 gchar *titles[] = {_("MIME type"), _("Size"), _("Name")};
3500 guint n_menu_entries;
3501 GtkStyle *style, *new_style;
3504 gboolean success[1];
3506 GtkWidget *popupmenu;
3507 GtkWidget *menuitem;
3508 GtkItemFactory *popupfactory;
3509 GtkItemFactory *ifactory;
3510 GtkWidget *tmpl_menu;
3516 GtkPspell * gtkpspell = NULL;
3519 g_return_val_if_fail(account != NULL, NULL);
3521 debug_print(_("Creating compose window...\n"));
3522 compose = g_new0(Compose, 1);
3524 compose->account = account;
3525 compose->orig_account = account;
3527 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
3528 gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
3529 gtk_widget_set_usize(window, -1, prefs_common.compose_height);
3530 gtk_signal_connect(GTK_OBJECT(window), "delete_event",
3531 GTK_SIGNAL_FUNC(compose_delete_cb), compose);
3532 gtk_signal_connect(GTK_OBJECT(window), "destroy",
3533 GTK_SIGNAL_FUNC(compose_destroy_cb), compose);
3534 gtk_signal_connect(GTK_OBJECT(window), "focus_in_event",
3535 GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
3536 gtk_signal_connect(GTK_OBJECT(window), "focus_out_event",
3537 GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
3538 gtk_widget_realize(window);
3540 gtkut_widget_set_composer_icon(window);
3542 vbox = gtk_vbox_new(FALSE, 0);
3543 gtk_container_add(GTK_CONTAINER(window), vbox);
3545 n_menu_entries = sizeof(compose_entries) / sizeof(compose_entries[0]);
3546 menubar = menubar_create(window, compose_entries,
3547 n_menu_entries, "<Compose>", compose);
3548 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
3550 handlebox = gtk_handle_box_new();
3551 gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
3553 compose_toolbar_create(compose, handlebox);
3555 vbox2 = gtk_vbox_new(FALSE, 2);
3556 gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
3557 gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
3559 table_vbox = gtk_vbox_new(FALSE, 0);
3560 gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
3561 gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
3565 notebook = gtk_notebook_new();
3566 gtk_widget_set_usize(notebook, -1, 180);
3567 gtk_widget_show(notebook);
3569 /* header labels and entries */
3570 header_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
3571 gtk_widget_show(header_scrolledwin);
3572 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
3573 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), header_scrolledwin, gtk_label_new(_("Header")));
3575 header_table = gtk_table_new(2, 2, FALSE);
3576 gtk_widget_show(header_table);
3577 gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
3578 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
3581 /* option menu for selecting accounts */
3582 hbox = gtk_hbox_new(FALSE, 0);
3583 label = gtk_label_new(prefs_common.trans_hdr ? _("From:") : "From:");
3584 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3585 gtk_table_attach(GTK_TABLE(header_table), hbox, 0, 1, count, count + 1,
3587 from_optmenu_hbox = compose_account_option_menu_create(compose);
3588 gtk_table_attach(GTK_TABLE(header_table), from_optmenu_hbox,
3589 1, 2, count, count + 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
3590 #if 0 /* NEW COMPOSE GUI */
3591 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
3596 compose_add_entry_field(header_table, &hbox, &subject_entry, &count,
3599 compose->header_table = header_table;
3600 compose->header_list = NULL;
3601 compose->header_nextrow = count;
3603 compose_create_header_entry(compose);
3605 #if 0 /* NEW COMPOSE GUI */
3606 compose_add_entry_field(table, &to_hbox, &to_entry, &count,
3608 gtk_table_set_row_spacing(GTK_TABLE(table), 0, 4);
3609 compose_add_entry_field(table, &newsgroups_hbox, &newsgroups_entry,
3610 &count, "Newsgroups:", FALSE);
3611 gtk_table_set_row_spacing(GTK_TABLE(table), 1, 4);
3613 gtk_table_set_row_spacing(GTK_TABLE(table), 2, 4);
3615 compose_add_entry_field(table, &cc_hbox, &cc_entry, &count,
3617 gtk_table_set_row_spacing(GTK_TABLE(table), 3, 4);
3618 compose_add_entry_field(table, &bcc_hbox, &bcc_entry, &count,
3620 gtk_table_set_row_spacing(GTK_TABLE(table), 4, 4);
3621 compose_add_entry_field(table, &reply_hbox, &reply_entry, &count,
3623 gtk_table_set_row_spacing(GTK_TABLE(table), 5, 4);
3624 compose_add_entry_field(table, &followup_hbox, &followup_entry, &count,
3625 "Followup-To:", FALSE);
3626 gtk_table_set_row_spacing(GTK_TABLE(table), 6, 4);
3628 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
3630 gtk_signal_connect(GTK_OBJECT(to_entry), "activate",
3631 GTK_SIGNAL_FUNC(to_activated), compose);
3632 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "activate",
3633 GTK_SIGNAL_FUNC(newsgroups_activated), compose);
3634 gtk_signal_connect(GTK_OBJECT(subject_entry), "activate",
3635 GTK_SIGNAL_FUNC(subject_activated), compose);
3636 gtk_signal_connect(GTK_OBJECT(cc_entry), "activate",
3637 GTK_SIGNAL_FUNC(cc_activated), compose);
3638 gtk_signal_connect(GTK_OBJECT(bcc_entry), "activate",
3639 GTK_SIGNAL_FUNC(bcc_activated), compose);
3640 gtk_signal_connect(GTK_OBJECT(reply_entry), "activate",
3641 GTK_SIGNAL_FUNC(replyto_activated), compose);
3642 gtk_signal_connect(GTK_OBJECT(followup_entry), "activate",
3643 GTK_SIGNAL_FUNC(followupto_activated), compose);
3645 gtk_signal_connect(GTK_OBJECT(subject_entry), "grab_focus",
3646 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3647 gtk_signal_connect(GTK_OBJECT(to_entry), "grab_focus",
3648 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3649 gtk_signal_connect(GTK_OBJECT(newsgroups_entry), "grab_focus",
3650 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3651 gtk_signal_connect(GTK_OBJECT(cc_entry), "grab_focus",
3652 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3653 gtk_signal_connect(GTK_OBJECT(bcc_entry), "grab_focus",
3654 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3655 gtk_signal_connect(GTK_OBJECT(reply_entry), "grab_focus",
3656 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3657 gtk_signal_connect(GTK_OBJECT(followup_entry), "grab_focus",
3658 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3661 /* attachment list */
3662 attach_scrwin = gtk_scrolled_window_new(NULL, NULL);
3663 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), attach_scrwin, gtk_label_new(_("Attachments")));
3664 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(attach_scrwin),
3665 GTK_POLICY_AUTOMATIC,
3667 gtk_widget_set_usize(attach_scrwin, -1, 80);
3669 attach_clist = gtk_clist_new_with_titles(N_ATTACH_COLS, titles);
3670 gtk_clist_set_column_justification(GTK_CLIST(attach_clist), COL_SIZE,
3672 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_MIMETYPE, 240);
3673 gtk_clist_set_column_width(GTK_CLIST(attach_clist), COL_SIZE, 64);
3674 gtk_clist_set_selection_mode(GTK_CLIST(attach_clist),
3675 GTK_SELECTION_EXTENDED);
3676 for (i = 0; i < N_ATTACH_COLS; i++)
3677 GTK_WIDGET_UNSET_FLAGS
3678 (GTK_CLIST(attach_clist)->column[i].button,
3680 gtk_container_add(GTK_CONTAINER(attach_scrwin), attach_clist);
3682 gtk_signal_connect(GTK_OBJECT(attach_clist), "select_row",
3683 GTK_SIGNAL_FUNC(attach_selected), compose);
3684 gtk_signal_connect(GTK_OBJECT(attach_clist), "button_press_event",
3685 GTK_SIGNAL_FUNC(attach_button_pressed), compose);
3686 gtk_signal_connect(GTK_OBJECT(attach_clist), "key_press_event",
3687 GTK_SIGNAL_FUNC(attach_key_pressed), compose);
3690 gtk_drag_dest_set(attach_clist,
3691 GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
3693 gtk_signal_connect(GTK_OBJECT(attach_clist), "drag_data_received",
3694 GTK_SIGNAL_FUNC(compose_attach_drag_received_cb),
3698 edit_vbox = gtk_vbox_new(FALSE, 0);
3699 #if 0 /* NEW COMPOSE GUI */
3700 gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
3704 ruler_hbox = gtk_hbox_new(FALSE, 0);
3705 gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
3707 ruler = gtk_shruler_new();
3708 gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
3709 gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
3711 gtk_widget_set_usize(ruler_hbox, 1, -1);
3714 scrolledwin = gtk_scrolled_window_new(NULL, NULL);
3715 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
3716 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
3717 gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
3718 gtk_widget_set_usize(scrolledwin, prefs_common.compose_width, -1);
3720 text = gtk_stext_new(gtk_scrolled_window_get_hadjustment
3721 (GTK_SCROLLED_WINDOW(scrolledwin)),
3722 gtk_scrolled_window_get_vadjustment
3723 (GTK_SCROLLED_WINDOW(scrolledwin)));
3724 GTK_STEXT(text)->default_tab_width = 8;
3725 gtk_stext_set_editable(GTK_STEXT(text), TRUE);
3727 if (prefs_common.block_cursor) {
3728 GTK_STEXT(text)->cursor_type = STEXT_CURSOR_BLOCK;
3731 if (prefs_common.smart_wrapping) {
3732 gtk_stext_set_word_wrap(GTK_STEXT(text), TRUE);
3733 gtk_stext_set_wrap_rmargin(GTK_STEXT(text), prefs_common.linewrap_len);
3736 gtk_container_add(GTK_CONTAINER(scrolledwin), text);
3738 gtk_signal_connect(GTK_OBJECT(text), "changed",
3739 GTK_SIGNAL_FUNC(compose_changed_cb), compose);
3740 gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
3741 GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
3742 gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
3743 GTK_SIGNAL_FUNC(compose_button_press_cb),
3746 gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
3747 GTK_SIGNAL_FUNC(compose_key_press_cb),
3750 gtk_signal_connect_after(GTK_OBJECT(text), "size_allocate",
3751 GTK_SIGNAL_FUNC(compose_edit_size_alloc),
3755 gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
3757 gtk_signal_connect(GTK_OBJECT(text), "drag_data_received",
3758 GTK_SIGNAL_FUNC(compose_insert_drag_received_cb),
3761 if (prefs_common.enable_pspell) {
3762 gtkpspell = gtkpspell_new_with_config(gtkpspellconfig,
3763 prefs_common.pspell_path,
3764 prefs_common.dictionary,
3766 conv_get_current_charset_str());
3767 if (gtkpspell == NULL)
3768 prefs_common.enable_pspell = FALSE;
3770 gtkpspell_attach(gtkpspell, GTK_STEXT(text));
3773 gtk_widget_show_all(vbox);
3775 /* pane between attach clist and text */
3776 paned = gtk_vpaned_new();
3777 gtk_container_add(GTK_CONTAINER(vbox2), paned);
3778 gtk_paned_add1(GTK_PANED(paned), notebook);
3779 gtk_paned_add2(GTK_PANED(paned), edit_vbox);
3780 gtk_widget_show_all(paned);
3782 style = gtk_widget_get_style(text);
3784 /* workaround for the slow down of GtkText when using Pixmap theme */
3785 if (style->engine) {
3786 GtkThemeEngine *engine;
3788 engine = style->engine;
3789 style->engine = NULL;
3790 new_style = gtk_style_copy(style);
3791 style->engine = engine;
3793 new_style = gtk_style_copy(style);