2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2002 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>
56 #include <sys/types.h>
60 /* #include <sys/utsname.h> */
66 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
73 #include "mainwindow.h"
76 #include "addressbook.h"
77 #include "folderview.h"
80 #include "stock_pixmap.h"
84 #include "customheader.h"
85 #include "prefs_common.h"
86 #include "prefs_account.h"
89 #include "procheader.h"
91 #include "statusbar.h"
98 #include "alertpanel.h"
99 #include "manage_window.h"
100 #include "gtkshruler.h"
102 #include "addr_compl.h"
103 #include "quote_fmt.h"
104 #include "template.h"
106 #include "foldersel.h"
107 #include "prefs_actions.h"
110 # include "rfc2015.h"
120 #define N_ATTACH_COLS 3
124 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
125 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
126 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
127 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
128 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
129 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
130 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
131 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
132 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
133 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
134 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
135 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
136 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
137 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
138 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END
139 } ComposeCallGtkSTextAction;
141 #define B64_LINE_SIZE 57
142 #define B64_BUFFSIZE 77
144 #define MAX_REFERENCES_LEN 999
146 static GdkColor quote_color = {0, 0, 0, 0xbfff};
148 static GList *compose_list = NULL;
150 Compose *compose_generic_new (PrefsAccount *account,
154 static Compose *compose_create (PrefsAccount *account,
156 static void compose_toolbar_create (Compose *compose,
157 GtkWidget *container);
158 static GtkWidget *compose_account_option_menu_create
160 static void compose_set_template_menu (Compose *compose);
161 static void compose_template_apply (Compose *compose,
163 static void compose_destroy (Compose *compose);
165 static void compose_entries_set (Compose *compose,
166 const gchar *mailto);
167 static gint compose_parse_header (Compose *compose,
169 static gchar *compose_parse_references (const gchar *ref,
172 static gchar *compose_quote_fmt (Compose *compose,
178 static void compose_reply_set_entry (Compose *compose,
183 followup_and_reply_to);
184 static void compose_reedit_set_entry (Compose *compose,
186 static void compose_insert_sig (Compose *compose);
187 static void compose_insert_file (Compose *compose,
189 static void compose_attach_append (Compose *compose,
191 ContentType cnttype);
192 static void compose_attach_append_with_type(Compose *compose,
195 ContentType cnttype);
196 static void compose_wrap_line (Compose *compose);
197 static void compose_wrap_line_all (Compose *compose);
198 static void compose_set_title (Compose *compose);
200 static PrefsAccount *compose_current_mail_account(void);
201 /* static gint compose_send (Compose *compose); */
202 static gint compose_write_to_file (Compose *compose,
205 static gint compose_write_body_to_file (Compose *compose,
207 static gint compose_save_to_outbox (Compose *compose,
209 static gint compose_remove_reedit_target (Compose *compose);
210 static gint compose_queue (Compose *compose,
213 static void compose_write_attach (Compose *compose,
215 static gint compose_write_headers (Compose *compose,
217 const gchar *charset,
218 EncodingType encoding,
221 static void compose_convert_header (gchar *dest,
225 static void compose_generate_msgid (Compose *compose,
229 static void compose_attach_info_free (AttachInfo *ainfo);
230 static void compose_attach_remove_selected (Compose *compose);
232 static void compose_attach_property (Compose *compose);
233 static void compose_attach_property_create (gboolean *cancelled);
234 static void attach_property_ok (GtkWidget *widget,
235 gboolean *cancelled);
236 static void attach_property_cancel (GtkWidget *widget,
237 gboolean *cancelled);
238 static gint attach_property_delete_event (GtkWidget *widget,
240 gboolean *cancelled);
241 static void attach_property_key_pressed (GtkWidget *widget,
243 gboolean *cancelled);
245 static void compose_exec_ext_editor (Compose *compose);
246 static gint compose_exec_ext_editor_real (const gchar *file);
247 static gboolean compose_ext_editor_kill (Compose *compose);
248 static void compose_input_cb (gpointer data,
250 GdkInputCondition condition);
251 static void compose_set_ext_editor_sensitive (Compose *compose,
254 static void compose_undo_state_changed (UndoMain *undostruct,
259 static gint calc_cursor_xpos (GtkSText *text,
263 static void compose_create_header_entry (Compose *compose);
264 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
266 /* callback functions */
268 static gboolean compose_edit_size_alloc (GtkEditable *widget,
269 GtkAllocation *allocation,
270 GtkSHRuler *shruler);
272 static void toolbar_send_cb (GtkWidget *widget,
274 static void toolbar_send_later_cb (GtkWidget *widget,
276 static void toolbar_draft_cb (GtkWidget *widget,
278 static void toolbar_insert_cb (GtkWidget *widget,
280 static void toolbar_attach_cb (GtkWidget *widget,
282 static void toolbar_sig_cb (GtkWidget *widget,
284 static void toolbar_ext_editor_cb (GtkWidget *widget,
286 static void toolbar_linewrap_cb (GtkWidget *widget,
288 static void toolbar_address_cb (GtkWidget *widget,
291 static void select_account (Compose *compose,
294 static void account_activated (GtkMenuItem *menuitem,
297 static void attach_selected (GtkCList *clist,
302 static void attach_button_pressed (GtkWidget *widget,
303 GdkEventButton *event,
305 static void attach_key_pressed (GtkWidget *widget,
309 static void compose_send_cb (gpointer data,
312 static void compose_send_later_cb (gpointer data,
316 static void compose_draft_cb (gpointer data,
320 static void compose_attach_cb (gpointer data,
323 static void compose_insert_file_cb (gpointer data,
327 static void compose_close_cb (gpointer data,
331 static void compose_address_cb (gpointer data,
334 static void compose_template_activate_cb(GtkWidget *widget,
337 static void compose_ext_editor_cb (gpointer data,
341 static gint compose_delete_cb (GtkWidget *widget,
344 static void compose_destroy_cb (GtkWidget *widget,
347 static void compose_undo_cb (Compose *compose);
348 static void compose_redo_cb (Compose *compose);
349 static void compose_cut_cb (Compose *compose);
350 static void compose_copy_cb (Compose *compose);
351 static void compose_paste_cb (Compose *compose);
352 static void compose_allsel_cb (Compose *compose);
354 static void compose_gtk_stext_action_cb (Compose *compose,
355 ComposeCallGtkSTextAction action);
357 static void compose_grab_focus_cb (GtkWidget *widget,
360 static void compose_changed_cb (GtkEditable *editable,
362 static void compose_button_press_cb (GtkWidget *widget,
363 GdkEventButton *event,
366 static void compose_key_press_cb (GtkWidget *widget,
372 static void compose_toggle_to_cb (gpointer data,
375 static void compose_toggle_cc_cb (gpointer data,
378 static void compose_toggle_bcc_cb (gpointer data,
381 static void compose_toggle_replyto_cb (gpointer data,
384 static void compose_toggle_followupto_cb(gpointer data,
387 static void compose_toggle_attach_cb (gpointer data,
391 static void compose_toggle_ruler_cb (gpointer data,
395 static void compose_toggle_sign_cb (gpointer data,
398 static void compose_toggle_encrypt_cb (gpointer data,
402 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
405 static void compose_attach_drag_received_cb (GtkWidget *widget,
406 GdkDragContext *drag_context,
409 GtkSelectionData *data,
413 static void compose_insert_drag_received_cb (GtkWidget *widget,
414 GdkDragContext *drag_context,
417 GtkSelectionData *data,
423 static void to_activated (GtkWidget *widget,
425 static void newsgroups_activated (GtkWidget *widget,
427 static void subject_activated (GtkWidget *widget,
429 static void cc_activated (GtkWidget *widget,
431 static void bcc_activated (GtkWidget *widget,
433 static void replyto_activated (GtkWidget *widget,
435 static void followupto_activated (GtkWidget *widget,
439 static void compose_attach_parts (Compose *compose,
442 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
444 gboolean ignore_replyto,
445 gboolean followup_and_reply_to,
448 void compose_headerentry_changed_cb (GtkWidget *entry,
449 ComposeHeaderEntry *headerentry);
450 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
452 ComposeHeaderEntry *headerentry);
454 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
457 static void compose_check_all (Compose *compose);
458 static void compose_highlight_all (Compose *compose);
459 static void compose_check_backwards (Compose *compose);
460 static void compose_check_forwards_go (Compose *compose);
463 static gboolean compose_send_control_enter (Compose *compose);
464 static void text_activated (GtkWidget *widget,
467 static GtkItemFactoryEntry compose_popup_entries[] =
469 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
470 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
471 {N_("/---"), NULL, NULL, 0, "<Separator>"},
472 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
475 static GtkItemFactoryEntry compose_entries[] =
477 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
478 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
479 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
480 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
481 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
482 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
484 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
485 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
486 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
487 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
488 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
489 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
490 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
491 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
492 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
493 {N_("/_Edit/A_dvanced/Move a character backward"),
495 compose_gtk_stext_action_cb,
496 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
498 {N_("/_Edit/A_dvanced/Move a character forward"),
500 compose_gtk_stext_action_cb,
501 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
503 {N_("/_Edit/A_dvanced/Move a word backward"),
505 compose_gtk_stext_action_cb,
506 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
508 {N_("/_Edit/A_dvanced/Move a word forward"),
510 compose_gtk_stext_action_cb,
511 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
513 {N_("/_Edit/A_dvanced/Move to beginning of line"),
514 NULL, /* "<control>A" */
515 compose_gtk_stext_action_cb,
516 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
518 {N_("/_Edit/A_dvanced/Move to end of line"),
520 compose_gtk_stext_action_cb,
521 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
523 {N_("/_Edit/A_dvanced/Move to previous line"),
525 compose_gtk_stext_action_cb,
526 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
528 {N_("/_Edit/A_dvanced/Move to next line"),
530 compose_gtk_stext_action_cb,
531 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
533 {N_("/_Edit/A_dvanced/Delete a character backward"),
535 compose_gtk_stext_action_cb,
536 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
538 {N_("/_Edit/A_dvanced/Delete a character forward"),
540 compose_gtk_stext_action_cb,
541 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
543 {N_("/_Edit/A_dvanced/Delete a word backward"),
544 NULL, /* "<control>W" */
545 compose_gtk_stext_action_cb,
546 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
548 {N_("/_Edit/A_dvanced/Delete a word forward"),
549 NULL, /* "<alt>D", */
550 compose_gtk_stext_action_cb,
551 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
553 {N_("/_Edit/A_dvanced/Delete line"),
555 compose_gtk_stext_action_cb,
556 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
558 {N_("/_Edit/A_dvanced/Delete entire line"),
560 compose_gtk_stext_action_cb,
561 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
563 {N_("/_Edit/A_dvanced/Delete to end of line"),
565 compose_gtk_stext_action_cb,
566 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
568 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
569 {N_("/_Edit/_Wrap current paragraph"),
570 "<control>L", compose_wrap_line, 0, NULL},
571 {N_("/_Edit/Wrap all long _lines"),
572 "<control><alt>L", compose_wrap_line_all, 0, NULL},
573 {N_("/_Edit/Edit with e_xternal editor"),
574 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
575 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
576 {N_("/_Edit/Actio_ns"), NULL, NULL, 0, "<Branch>"},
578 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
579 {N_("/_Spelling/_Check all or check selection"),
580 NULL, compose_check_all, 0, NULL},
581 {N_("/_Spelling/_Highlight all misspelled words"),
582 NULL, compose_highlight_all, 0, NULL},
583 {N_("/_Spelling/Check _backwards misspelled word"),
584 NULL, compose_check_backwards , 0, NULL},
585 {N_("/_Spelling/_Forward to next misspelled word"),
586 NULL, compose_check_forwards_go, 0, NULL},
587 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
588 {N_("/_Spelling/_Spelling Configuration"),
589 NULL, NULL, 0, "<Branch>"},
591 #if 0 /* NEW COMPOSE GUI */
592 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
593 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
594 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
595 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
596 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
597 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
598 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
599 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
600 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
601 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
602 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
604 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
605 {N_("/_Message/_Send"), "<control>Return",
606 compose_send_cb, 0, NULL},
607 {N_("/_Message/Send _later"), "<shift><control>S",
608 compose_send_later_cb, 0, NULL},
609 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
610 {N_("/_Message/Save to _draft folder"),
611 "<shift><control>D", compose_draft_cb, 0, NULL},
612 {N_("/_Message/Save and _keep editing"),
613 "<control>S", compose_draft_cb, 1, NULL},
614 #if 0 /* NEW COMPOSE GUI */
615 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
616 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
617 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
618 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
619 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
620 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
621 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
622 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
623 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
626 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
627 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
628 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
629 #endif /* USE_GPGME */
630 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
631 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
632 {N_("/_Tool"), NULL, NULL, 0, "<Branch>"},
633 {N_("/_Tool/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
634 {N_("/_Tool/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
635 {N_("/_Tool/_Template"), NULL, NULL, 0, "<Branch>"},
636 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
637 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
640 static GtkTargetEntry compose_mime_types[] =
642 {"text/uri-list", 0, 0}
645 Compose *compose_new(PrefsAccount *account)
647 return compose_generic_new(account, NULL, NULL);
650 Compose *compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
654 GtkItemFactory *ifactory;
656 c = compose_generic_new(account, NULL, NULL);
658 filename = procmsg_get_message_file(msginfo);
659 if (filename == NULL)
662 c->bounce_filename = filename;
664 if (msginfo->subject)
665 gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
667 gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
669 compose_quote_fmt(c, msginfo, "%M", NULL, NULL);
670 gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
672 ifactory = gtk_item_factory_from_widget(c->popupmenu);
673 menu_set_sensitive(ifactory, "/Add...", FALSE);
674 menu_set_sensitive(ifactory, "/Remove", FALSE);
675 menu_set_sensitive(ifactory, "/Property...", FALSE);
677 ifactory = gtk_item_factory_from_widget(c->menubar);
678 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
679 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
680 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
681 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
682 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
683 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
684 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
685 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
687 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
688 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
690 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
691 menu_set_sensitive(ifactory, "/Tool/Template", FALSE);
693 gtk_widget_set_sensitive(c->insert_btn, FALSE);
694 gtk_widget_set_sensitive(c->attach_btn, FALSE);
695 gtk_widget_set_sensitive(c->sig_btn, FALSE);
696 gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
697 gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
702 Compose *compose_new_with_recipient(PrefsAccount *account, const gchar *mailto)
704 return compose_generic_new(account, mailto, NULL);
707 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
709 return compose_generic_new(account, NULL, item);
712 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item)
716 if (item && item->prefs && item->prefs->enable_default_account)
717 account = account_find_from_id(item->prefs->default_account);
719 if (!account) account = cur_account;
720 g_return_val_if_fail(account != NULL, NULL);
722 compose = compose_create(account, COMPOSE_NEW);
723 compose->replyinfo = NULL;
725 if (prefs_common.auto_sig)
726 compose_insert_sig(compose);
727 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
728 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
730 if (account->protocol != A_NNTP) {
732 compose_entries_set(compose, mailto);
734 } else if(item && item->prefs->enable_default_to) {
735 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
737 if (item && item->ret_rcpt) {
738 GtkItemFactory *ifactory;
740 ifactory = gtk_item_factory_from_widget(compose->menubar);
741 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
745 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
748 compose_show_first_last_header(compose, TRUE);
750 /* Set save folder */
751 if(item && item->prefs && item->prefs->save_copy_to_folder) {
752 gchar *folderidentifier;
754 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
755 folderidentifier = folder_item_get_identifier(item);
756 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
757 g_free(folderidentifier);
760 gtk_widget_grab_focus(compose->header_last->entry);
762 if (prefs_common.auto_exteditor)
763 compose_exec_ext_editor(compose);
768 #define CHANGE_FLAGS(msginfo) \
770 if (msginfo->folder->folder->change_flags != NULL) \
771 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
777 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
778 const gchar *followupto, gchar * to)
782 if (!account) account = cur_account;
783 g_return_val_if_fail(account != NULL, NULL);
784 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
786 compose = compose_create(account, COMPOSE_NEW);
788 if (prefs_common.auto_sig)
789 compose_insert_sig(compose);
790 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
791 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
793 compose_entry_append(compose, to, COMPOSE_TO);
794 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
795 gtk_widget_grab_focus(compose->subject_entry);
801 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
802 gboolean ignore_replyto, const gchar *body)
804 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE,
808 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
810 gboolean ignore_replyto,
813 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE,
817 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
819 gboolean ignore_replyto,
820 gboolean followup_and_reply_to,
824 PrefsAccount *account;
825 PrefsAccount *reply_account;
828 g_return_if_fail(msginfo != NULL);
829 g_return_if_fail(msginfo->folder != NULL);
832 /* select the account set in folderitem's property (if enabled) */
833 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
834 account = account_find_from_id(msginfo->folder->prefs->default_account);
836 /* select the account for the whole folder (IMAP / NNTP) */
838 /* FIXME: this is not right, because folder may be nested. we should
839 * ascend the tree until we find a parent with proper account
841 account = msginfo->folder->folder->account;
843 /* select account by to: and cc: header if enabled */
844 if (prefs_common.reply_account_autosel) {
845 if (!account && msginfo->to) {
847 Xstrdup_a(to, msginfo->to, return);
849 account = account_find_from_address(to);
853 if(!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
855 account = account_find_from_address(cc);
860 /* select current account */
861 if (!account) account = cur_account;
862 g_return_if_fail(account != NULL);
864 if (ignore_replyto && account->protocol == A_NNTP &&
865 !followup_and_reply_to) {
867 account_find_from_address(account->address);
869 reply_account = compose_current_mail_account();
873 reply_account = account;
875 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
876 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
877 if (MSG_IS_IMAP(msginfo->flags))
878 imap_msg_set_perm_flags(msginfo, MSG_REPLIED);
879 CHANGE_FLAGS(msginfo);
881 compose = compose_create(account, COMPOSE_REPLY);
882 compose->replyinfo = procmsg_msginfo_copy(msginfo);
884 #if 0 /* NEW COMPOSE GUI */
885 if (followup_and_reply_to) {
886 gtk_widget_show(compose->to_hbox);
887 gtk_widget_show(compose->to_entry);
888 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
889 compose->use_to = TRUE;
892 if (msginfo->folder && msginfo->folder->ret_rcpt) {
893 GtkItemFactory *ifactory;
895 ifactory = gtk_item_factory_from_widget(compose->menubar);
896 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
899 /* Set save folder */
900 if(msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
901 gchar *folderidentifier;
903 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
904 folderidentifier = folder_item_get_identifier(msginfo->folder);
905 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
906 g_free(folderidentifier);
909 if (compose_parse_header(compose, msginfo) < 0) return;
910 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
911 followup_and_reply_to);
912 compose_show_first_last_header(compose, TRUE);
914 text = GTK_STEXT(compose->text);
915 gtk_stext_freeze(text);
921 if (prefs_common.quotemark && *prefs_common.quotemark)
922 qmark = prefs_common.quotemark;
926 quote_str = compose_quote_fmt(compose, msginfo,
927 prefs_common.quotefmt,
931 if (prefs_common.auto_sig)
932 compose_insert_sig(compose);
934 if (quote && prefs_common.linewrap_quote)
935 compose_wrap_line_all(compose);
937 gtk_editable_set_position(GTK_EDITABLE(text), 0);
938 gtk_stext_set_point(text, 0);
940 gtk_stext_thaw(text);
941 gtk_widget_grab_focus(compose->text);
943 if (prefs_common.auto_exteditor)
944 compose_exec_ext_editor(compose);
947 static void set_toolbar_style(Compose *compose);
949 static gchar *procmime_get_file_name(MimeInfo *mimeinfo)
954 g_return_val_if_fail(mimeinfo != NULL, NULL);
956 base = mimeinfo->filename ? mimeinfo->filename
957 : mimeinfo->name ? mimeinfo->name : NULL;
959 if (MIME_TEXT_HTML == mimeinfo->mime_type && base == NULL){
960 filename = g_strdup_printf("%s%smimetmp.%08x.html",
967 base = base ? base : "";
968 base = g_basename(base);
970 filename = g_strdup_printf("%s%smimetmp.%08x",
978 filename = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
984 static gchar *mime_extract_file(gchar *source, MimeInfo *partinfo)
988 if (!partinfo) return NULL;
990 filename = procmime_get_file_name(partinfo);
992 if (procmime_get_part(filename, source, partinfo) < 0)
994 (_("Can't get the part of multipart message."));
999 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
1004 MsgInfo *tmpmsginfo;
1007 gint boundary_len = 0;
1008 gchar buf[BUFFSIZE];
1009 glong fpos, prev_fpos;
1014 g_return_if_fail(msginfo != NULL);
1018 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
1019 mimeinfo = procmime_scan_mime_header(fp, MIME_TEXT);
1020 if (!mimeinfo) break;
1022 if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
1023 rfc2015_is_encrypted(mimeinfo)) {
1024 MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED);
1026 if (MSG_IS_ENCRYPTED(msginfo->flags) &&
1027 !msginfo->plaintext_file &&
1028 !msginfo->decryption_failed) {
1029 rfc2015_decrypt_message(msginfo, mimeinfo, fp);
1030 if (msginfo->plaintext_file &&
1031 !msginfo->decryption_failed) {
1039 #else /* !USE_GPGME */
1040 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
1041 mimeinfo = procmime_scan_mime_header(fp, MIME_TEXT);
1042 #endif /* USE_GPGME */
1045 if (!mimeinfo) return;
1046 if (mimeinfo->mime_type == MIME_TEXT)
1049 if ((fp = procmsg_open_message(msginfo)) == NULL) return;
1051 g_return_if_fail(mimeinfo != NULL);
1052 g_return_if_fail(mimeinfo->mime_type != MIME_TEXT);
1054 if (mimeinfo->mime_type == MIME_MULTIPART) {
1055 g_return_if_fail(mimeinfo->boundary != NULL);
1056 g_return_if_fail(mimeinfo->sub == NULL);
1058 g_return_if_fail(fp != NULL);
1060 boundary = mimeinfo->boundary;
1063 boundary_len = strlen(boundary);
1065 /* look for first boundary */
1066 while ((p = fgets(buf, sizeof(buf), fp)) != NULL)
1067 if (IS_BOUNDARY(buf, boundary, boundary_len)) break;
1074 if ((fpos = ftell(fp)) < 0) {
1080 for (npart = 0;; npart++) {
1082 gboolean eom = FALSE;
1086 partinfo = procmime_scan_mime_header(fp, MIME_TEXT);
1087 if (!partinfo) break;
1090 procmime_mimeinfo_insert(mimeinfo, partinfo);
1092 procmime_mimeinfo_free(partinfo);
1094 /* look for next boundary */
1096 while ((p = fgets(buf, sizeof(buf), fp)) != NULL) {
1097 if (IS_BOUNDARY(buf, boundary, boundary_len)) {
1098 if (buf[2 + boundary_len] == '-' &&
1099 buf[2 + boundary_len + 1] == '-')
1105 eom = TRUE; /* broken MIME message */
1108 partinfo->size = fpos - prev_fpos - strlen(buf);
1113 source = procmsg_get_message_file_path(msginfo);
1115 g_return_if_fail(mimeinfo != NULL);
1117 if (!mimeinfo->main && mimeinfo->parent)
1119 filename = mime_extract_file(source, mimeinfo);
1121 compose_attach_append_with_type(compose, filename,
1122 mimeinfo->content_type,
1123 mimeinfo->mime_type);
1128 if (mimeinfo->sub && mimeinfo->sub->children)
1130 filename = mime_extract_file(source, mimeinfo->sub);
1132 compose_attach_append_with_type(compose, filename,
1133 mimeinfo->content_type,
1134 mimeinfo->sub->mime_type);
1139 if (mimeinfo->children) {
1142 child = mimeinfo->children;
1144 filename = mime_extract_file(source, child);
1146 compose_attach_append_with_type(compose, filename,
1147 child->content_type,
1152 child = child->next;
1158 procmime_mimeinfo_free_all(mimeinfo);
1162 #define INSERT_FW_HEADER(var, hdr) \
1163 if (msginfo->var && *msginfo->var) { \
1164 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1165 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1166 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1169 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1170 gboolean as_attach, const gchar *body)
1173 /* PrefsAccount *account; */
1176 g_return_val_if_fail(msginfo != NULL, NULL);
1177 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1179 account = msginfo->folder->folder->account;
1180 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1182 Xstrdup_a(to, msginfo->to, return NULL);
1183 extract_address(to);
1184 account = account_find_from_address(to);
1187 if(!account && prefs_common.forward_account_autosel) {
1189 if(!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1190 extract_address(cc);
1191 account = account_find_from_address(cc);
1195 if (account == NULL) {
1196 account = cur_account;
1198 account = msginfo->folder->folder->account;
1199 if (!account) account = cur_account;
1202 g_return_val_if_fail(account != NULL, NULL);
1204 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1205 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1206 if (MSG_IS_IMAP(msginfo->flags))
1207 imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
1208 CHANGE_FLAGS(msginfo);
1210 compose = compose_create(account, COMPOSE_FORWARD);
1212 if (msginfo->subject && *msginfo->subject) {
1213 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1214 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1218 text = GTK_STEXT(compose->text);
1219 gtk_stext_freeze(text);
1224 msgfile = procmsg_get_message_file_path(msginfo);
1225 if (!is_file_exist(msgfile))
1226 g_warning(_("%s: file not exist\n"), msgfile);
1228 compose_attach_append(compose, msgfile,
1229 MIME_MESSAGE_RFC822);
1236 if (prefs_common.fw_quotemark && *prefs_common.fw_quotemark)
1237 qmark = prefs_common.fw_quotemark;
1241 quote_str = compose_quote_fmt(compose, msginfo,
1242 prefs_common.fw_quotefmt, qmark,
1244 compose_attach_parts(compose, msginfo);
1247 if (prefs_common.auto_sig)
1248 compose_insert_sig(compose);
1250 if (prefs_common.linewrap_quote)
1251 compose_wrap_line_all(compose);
1253 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1254 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1256 gtk_stext_thaw(text);
1257 #if 0 /* NEW COMPOSE GUI */
1258 if (account->protocol != A_NNTP)
1259 gtk_widget_grab_focus(compose->to_entry);
1261 gtk_widget_grab_focus(compose->newsgroups_entry);
1263 gtk_widget_grab_focus(compose->header_last->entry);
1265 if (prefs_common.auto_exteditor)
1266 compose_exec_ext_editor(compose);
1271 #undef INSERT_FW_HEADER
1273 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1280 g_return_val_if_fail(msginfo_list != NULL, NULL);
1282 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1283 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1287 if (account == NULL) {
1288 account = cur_account;
1290 account = msginfo->folder->folder->account;
1291 if (!account) account = cur_account;
1294 g_return_val_if_fail(account != NULL, NULL);
1296 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1297 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1298 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1299 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1302 compose = compose_create(account, COMPOSE_FORWARD);
1304 text = GTK_STEXT(compose->text);
1305 gtk_stext_freeze(text);
1307 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1308 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1309 if (!is_file_exist(msgfile))
1310 g_warning(_("%s: file not exist\n"), msgfile);
1312 compose_attach_append(compose, msgfile,
1313 MIME_MESSAGE_RFC822);
1317 if (prefs_common.auto_sig)
1318 compose_insert_sig(compose);
1320 if (prefs_common.linewrap_quote)
1321 compose_wrap_line_all(compose);
1323 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1324 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1326 gtk_stext_thaw(text);
1327 #if 0 /* NEW COMPOSE GUI */
1328 if (account->protocol != A_NNTP)
1329 gtk_widget_grab_focus(compose->to_entry);
1331 gtk_widget_grab_focus(compose->newsgroups_entry);
1337 void compose_reedit(MsgInfo *msginfo)
1340 PrefsAccount *account = NULL;
1343 gchar buf[BUFFSIZE];
1345 g_return_if_fail(msginfo != NULL);
1346 g_return_if_fail(msginfo->folder != NULL);
1348 if (msginfo->folder->stype == F_QUEUE) {
1349 gchar queueheader_buf[BUFFSIZE];
1352 /* Select Account from queue headers */
1353 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1354 sizeof(queueheader_buf), "NAID:")) {
1355 id = atoi(&queueheader_buf[5]);
1356 account = account_find_from_id(id);
1358 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1359 sizeof(queueheader_buf), "MAID:")) {
1360 id = atoi(&queueheader_buf[5]);
1361 account = account_find_from_id(id);
1363 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1364 sizeof(queueheader_buf), "S:")) {
1365 account = account_find_from_address(queueheader_buf);
1368 account = msginfo->folder->folder->account;
1370 if (!account && prefs_common.reedit_account_autosel) {
1371 gchar from[BUFFSIZE];
1372 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1373 extract_address(from);
1374 account = account_find_from_address(from);
1377 if (!account) account = cur_account;
1378 g_return_if_fail(account != NULL);
1380 compose = compose_create(account, COMPOSE_REEDIT);
1381 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1383 if (msginfo->folder->stype == F_QUEUE) {
1384 gchar queueheader_buf[BUFFSIZE];
1386 /* Set message save folder */
1387 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1390 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1391 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1392 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1396 if (compose_parse_header(compose, msginfo) < 0) return;
1397 compose_reedit_set_entry(compose, msginfo);
1399 text = GTK_STEXT(compose->text);
1400 gtk_stext_freeze(text);
1402 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1403 g_warning(_("Can't get text part\n"));
1405 while (fgets(buf, sizeof(buf), fp) != NULL)
1406 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1409 compose_attach_parts(compose, msginfo);
1411 gtk_stext_thaw(text);
1412 gtk_widget_grab_focus(compose->text);
1414 if (prefs_common.auto_exteditor)
1415 compose_exec_ext_editor(compose);
1418 GList *compose_get_compose_list(void)
1420 return compose_list;
1423 void compose_entry_append(Compose *compose, const gchar *address,
1424 ComposeEntryType type)
1430 if (!address || *address == '\0') return;
1432 #if 0 /* NEW COMPOSE GUI */
1435 entry = GTK_ENTRY(compose->cc_entry);
1438 entry = GTK_ENTRY(compose->bcc_entry);
1440 case COMPOSE_NEWSGROUPS:
1441 entry = GTK_ENTRY(compose->newsgroups_entry);
1445 entry = GTK_ENTRY(compose->to_entry);
1449 text = gtk_entry_get_text(entry);
1451 gtk_entry_append_text(entry, ", ");
1452 gtk_entry_append_text(entry, address);
1460 header = N_("Bcc:");
1462 case COMPOSE_REPLYTO:
1463 header = N_("Reply-To:");
1465 case COMPOSE_NEWSGROUPS:
1466 header = N_("Newsgroups:");
1468 case COMPOSE_FOLLOWUPTO:
1469 header = N_( "Followup-To:");
1476 header = prefs_common.trans_hdr ? gettext(header) : header;
1478 compose_add_header_entry(compose, header, (gchar *)address);
1481 static void compose_entries_set(Compose *compose, const gchar *mailto)
1483 gchar *subject = NULL;
1491 Xstrdup_a(tmp_mailto, mailto, return);
1495 p = strchr(tmp_mailto, '?');
1502 gchar *field, *value;
1519 if (*value == '\0') continue;
1521 if (!g_strcasecmp(field, "subject")) {
1522 Xalloca(subject, strlen(value) + 1, return);
1523 decode_uri(subject, value);
1524 } else if (!g_strcasecmp(field, "cc")) {
1526 } else if (!g_strcasecmp(field, "bcc")) {
1528 } else if (!g_strcasecmp(field, "body")) {
1529 Xalloca(body, strlen(value) + 1, return);
1530 decode_uri(body, value);
1535 compose_entry_append(compose, to, COMPOSE_TO);
1537 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1539 compose_entry_append(compose, cc, COMPOSE_CC);
1541 compose_entry_append(compose, bcc, COMPOSE_BCC);
1543 gtk_stext_insert(GTK_STEXT(compose->text),
1544 NULL, NULL, NULL, body, -1);
1545 gtk_stext_insert(GTK_STEXT(compose->text),
1546 NULL, NULL, NULL, "\n", 1);
1550 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1552 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1553 {"Cc:", NULL, FALSE},
1554 {"References:", NULL, FALSE},
1555 {"Bcc:", NULL, FALSE},
1556 {"Newsgroups:", NULL, FALSE},
1557 {"Followup-To:", NULL, FALSE},
1558 {"X-Mailing-List:", NULL, FALSE},
1559 {"X-BeenThere:", NULL, FALSE},
1560 {NULL, NULL, FALSE}};
1570 H_X_MAILING_LIST = 6,
1576 g_return_val_if_fail(msginfo != NULL, -1);
1578 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1579 procheader_get_header_fields(fp, hentry);
1582 if (hentry[H_REPLY_TO].body != NULL) {
1583 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1584 compose->replyto = hentry[H_REPLY_TO].body;
1585 hentry[H_REPLY_TO].body = NULL;
1587 if (hentry[H_CC].body != NULL) {
1588 conv_unmime_header_overwrite(hentry[H_CC].body);
1589 compose->cc = hentry[H_CC].body;
1590 hentry[H_CC].body = NULL;
1592 if (hentry[H_X_MAILING_LIST].body != NULL) {
1593 /* this is good enough to parse debian-devel */
1594 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1595 g_return_val_if_fail(buf != NULL, -1 );
1596 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1597 compose->mailinglist = g_strdup(buf);
1599 g_free(hentry[H_X_MAILING_LIST].body);
1600 hentry[H_X_MAILING_LIST].body = NULL ;
1602 if (hentry[H_X_BEENTHERE].body != NULL) {
1603 /* this is good enough to parse the sylpheed-claws lists */
1604 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1605 g_return_val_if_fail(buf != NULL, -1 );
1606 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1607 compose->mailinglist = g_strdup(buf);
1609 g_free(hentry[H_X_BEENTHERE].body);
1610 hentry[H_X_BEENTHERE].body = NULL ;
1612 if (hentry[H_REFERENCES].body != NULL) {
1613 if (compose->mode == COMPOSE_REEDIT)
1614 compose->references = hentry[H_REFERENCES].body;
1616 compose->references = compose_parse_references
1617 (hentry[H_REFERENCES].body, msginfo->msgid);
1618 g_free(hentry[H_REFERENCES].body);
1620 hentry[H_REFERENCES].body = NULL;
1622 if (hentry[H_BCC].body != NULL) {
1623 if (compose->mode == COMPOSE_REEDIT) {
1624 conv_unmime_header_overwrite(hentry[H_BCC].body);
1625 compose->bcc = hentry[H_BCC].body;
1627 g_free(hentry[H_BCC].body);
1628 hentry[H_BCC].body = NULL;
1630 if (hentry[H_NEWSGROUPS].body != NULL) {
1631 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1632 hentry[H_NEWSGROUPS].body = NULL;
1634 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1635 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1636 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1637 hentry[H_FOLLOWUP_TO].body = NULL;
1640 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1641 compose->inreplyto = g_strdup(msginfo->inreplyto);
1642 else if (compose->mode != COMPOSE_REEDIT &&
1643 msginfo->msgid && *msginfo->msgid) {
1644 compose->inreplyto = g_strdup(msginfo->msgid);
1646 if (!compose->references) {
1647 if (msginfo->inreplyto && *msginfo->inreplyto)
1648 compose->references =
1649 g_strdup_printf("<%s>\n\t<%s>",
1653 compose->references =
1654 g_strconcat("<", msginfo->msgid, ">",
1662 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1664 GSList *ref_id_list, *cur;
1668 ref_id_list = references_list_append(NULL, ref);
1669 if (!ref_id_list) return NULL;
1670 if (msgid && *msgid)
1671 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1676 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1677 /* "<" + Message-ID + ">" + CR+LF+TAB */
1678 len += strlen((gchar *)cur->data) + 5;
1680 if (len > MAX_REFERENCES_LEN) {
1681 /* remove second message-ID */
1682 if (ref_id_list && ref_id_list->next &&
1683 ref_id_list->next->next) {
1684 g_free(ref_id_list->next->data);
1685 ref_id_list = g_slist_remove
1686 (ref_id_list, ref_id_list->next->data);
1688 slist_free_strings(ref_id_list);
1689 g_slist_free(ref_id_list);
1696 new_ref = g_string_new("");
1697 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1698 if (new_ref->len > 0)
1699 g_string_append(new_ref, "\n\t");
1700 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1703 slist_free_strings(ref_id_list);
1704 g_slist_free(ref_id_list);
1706 new_ref_str = new_ref->str;
1707 g_string_free(new_ref, FALSE);
1712 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1713 const gchar *fmt, const gchar *qmark,
1716 GtkSText *text = GTK_STEXT(compose->text);
1717 gchar *quote_str = NULL;
1722 if (qmark != NULL) {
1723 quote_fmt_init(msginfo, NULL, NULL);
1724 quote_fmt_scan_string(qmark);
1727 buf = quote_fmt_get_buffer();
1729 alertpanel_error(_("Quote mark format error."));
1731 Xstrdup_a(quote_str, buf, return NULL)
1734 if (fmt && *fmt != '\0') {
1735 quote_fmt_init(msginfo, quote_str, body);
1736 quote_fmt_scan_string(fmt);
1739 buf = quote_fmt_get_buffer();
1741 alertpanel_error(_("Message reply/forward format error."));
1747 gtk_stext_freeze(text);
1749 for (p = buf; *p != '\0'; ) {
1750 lastp = strchr(p, '\n');
1751 len = lastp ? lastp - p + 1 : -1;
1752 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1759 gtk_stext_thaw(text);
1764 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1765 gboolean to_all, gboolean ignore_replyto,
1766 gboolean followup_and_reply_to)
1768 GSList *cc_list = NULL;
1771 gchar *replyto = NULL;
1772 GHashTable *to_table;
1774 g_return_if_fail(compose->account != NULL);
1775 g_return_if_fail(msginfo != NULL);
1777 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1778 compose_entry_append(compose,
1779 ((compose->replyto && !ignore_replyto)
1781 : (compose->mailinglist && !ignore_replyto)
1782 ? compose->mailinglist
1783 : msginfo->from ? msginfo->from : ""),
1786 if (compose->account->protocol == A_NNTP) {
1788 compose_entry_append
1789 (compose, msginfo->from ? msginfo->from : "",
1792 compose_entry_append
1794 compose->followup_to ? compose->followup_to
1795 : compose->newsgroups ? compose->newsgroups
1797 COMPOSE_NEWSGROUPS);
1800 if (msginfo->subject && *msginfo->subject) {
1801 gchar *buf, *buf2, *p;
1803 buf = g_strdup(msginfo->subject);
1804 while (!strncasecmp(buf, "Re:", 3)) {
1806 while (isspace(*p)) p++;
1807 memmove(buf, p, strlen(p) + 1);
1810 buf2 = g_strdup_printf("Re: %s", buf);
1811 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1815 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1817 if (!to_all || compose->account->protocol == A_NNTP) return;
1819 if (compose->replyto) {
1820 Xstrdup_a(replyto, compose->replyto, return);
1821 extract_address(replyto);
1823 if (msginfo->from) {
1824 Xstrdup_a(from, msginfo->from, return);
1825 extract_address(from);
1828 if (compose->mailinglist && from) {
1829 cc_list = address_list_append(cc_list, from);
1832 if (replyto && from)
1833 cc_list = address_list_append(cc_list, from);
1835 if (!compose->mailinglist)
1836 cc_list = address_list_append(cc_list, msginfo->to);
1838 cc_list = address_list_append(cc_list, compose->cc);
1840 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1842 g_hash_table_insert(to_table, replyto, GINT_TO_POINTER(1));
1843 if (compose->account)
1844 g_hash_table_insert(to_table, compose->account->address,
1845 GINT_TO_POINTER(1));
1847 /* remove address on To: and that of current account */
1848 for (cur = cc_list; cur != NULL; ) {
1849 GSList *next = cur->next;
1851 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1852 cc_list = g_slist_remove(cc_list, cur->data);
1854 g_hash_table_insert(to_table, cur->data, cur);
1858 g_hash_table_destroy(to_table);
1861 for (cur = cc_list; cur != NULL; cur = cur->next)
1862 compose_entry_append(compose, (gchar *)cur->data,
1864 slist_free_strings(cc_list);
1865 g_slist_free(cc_list);
1869 #define SET_ENTRY(entry, str) \
1872 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1875 #define SET_ADDRESS(type, str) \
1878 compose_entry_append(compose, str, type); \
1881 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1883 g_return_if_fail(msginfo != NULL);
1885 SET_ENTRY(subject_entry, msginfo->subject);
1886 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1887 SET_ADDRESS(COMPOSE_CC, compose->cc);
1888 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1889 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1891 compose_show_first_last_header(compose, TRUE);
1893 #if 0 /* NEW COMPOSE GUI */
1895 GtkItemFactory *ifactory;
1896 GtkWidget *menuitem;
1898 ifactory = gtk_item_factory_from_widget(compose->menubar);
1899 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
1900 gtk_check_menu_item_set_active
1901 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1903 if (compose->replyto) {
1904 GtkItemFactory *ifactory;
1905 GtkWidget *menuitem;
1907 ifactory = gtk_item_factory_from_widget(compose->menubar);
1908 menuitem = gtk_item_factory_get_item
1909 (ifactory, "/View/Reply to");
1910 gtk_check_menu_item_set_active
1911 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1919 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1926 size_t buf_len = 128;
1928 if (strlen(sigfile) < 2)
1931 sigprg = popen(sigfile+1, "r");
1934 buf = g_malloc(buf_len);
1937 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1938 "Unable to insert signature (malloc failed)\n", -1);
1944 while (!feof(sigprg)) {
1945 bzero(buf, buf_len);
1946 fread(buf, buf_len-1, 1, sigprg);
1947 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1955 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1956 "Can't exec file: ", -1);
1957 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1962 static void compose_insert_sig(Compose *compose)
1966 if (compose->account && compose->account->sig_path)
1967 sigfile = g_strdup(compose->account->sig_path);
1969 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1970 DEFAULT_SIGNATURE, NULL);
1972 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1977 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1978 if (prefs_common.sig_sep) {
1979 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1980 prefs_common.sig_sep, -1);
1981 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1985 if (sigfile[0] == '|')
1986 compose_exec_sig(compose, sigfile);
1988 compose_insert_file(compose, sigfile);
1992 static void compose_insert_file(Compose *compose, const gchar *file)
1994 GtkSText *text = GTK_STEXT(compose->text);
1995 gchar buf[BUFFSIZE];
1999 g_return_if_fail(file != NULL);
2001 if ((fp = fopen(file, "r")) == NULL) {
2002 FILE_OP_ERROR(file, "fopen");
2006 gtk_stext_freeze(text);
2008 while (fgets(buf, sizeof(buf), fp) != NULL) {
2009 /* strip <CR> if DOS/Windows file,
2010 replace <CR> with <LF> if Macintosh file. */
2013 if (len > 0 && buf[len - 1] != '\n') {
2015 if (buf[len] == '\r') buf[len] = '\n';
2017 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
2020 gtk_stext_thaw(text);
2025 static void compose_attach_info(Compose * compose, AttachInfo * ainfo,
2026 ContentType cnttype)
2028 gchar *text[N_ATTACH_COLS];
2031 text[COL_MIMETYPE] = ainfo->content_type;
2032 text[COL_SIZE] = to_human_readable(ainfo->size);
2033 text[COL_NAME] = ainfo->name;
2035 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2036 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2038 if (cnttype != MIME_MESSAGE_RFC822)
2039 compose_changed_cb(NULL, compose);
2042 static void compose_attach_append_with_type(Compose *compose,
2045 ContentType cnttype)
2050 if (!is_file_exist(file)) {
2051 g_warning(_("File %s doesn't exist\n"), file);
2054 if ((size = get_file_size(file)) < 0) {
2055 g_warning(_("Can't get file size of %s\n"), file);
2059 alertpanel_notice(_("File %s is empty\n"), file);
2062 #if 0 /* NEW COMPOSE GUI */
2063 if (!compose->use_attach) {
2064 GtkItemFactory *ifactory;
2065 GtkWidget *menuitem;
2067 ifactory = gtk_item_factory_from_widget(compose->menubar);
2068 menuitem = gtk_item_factory_get_item(ifactory,
2070 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2074 ainfo = g_new0(AttachInfo, 1);
2075 ainfo->file = g_strdup(file);
2077 if (cnttype == MIME_MESSAGE_RFC822) {
2078 ainfo->encoding = ENC_7BIT;
2079 ainfo->name = g_strdup_printf(_("Message: %s"),
2082 ainfo->encoding = ENC_BASE64;
2083 ainfo->name = g_strdup(g_basename(file));
2086 ainfo->content_type = g_strdup(type);
2089 compose_attach_info(compose, ainfo, cnttype);
2092 static void compose_attach_append(Compose *compose, const gchar *file,
2093 ContentType cnttype)
2096 gchar *text[N_ATTACH_COLS];
2100 if (!is_file_exist(file)) {
2101 g_warning(_("File %s doesn't exist\n"), file);
2104 if ((size = get_file_size(file)) < 0) {
2105 g_warning(_("Can't get file size of %s\n"), file);
2109 alertpanel_notice(_("File %s is empty\n"), file);
2112 #if 0 /* NEW COMPOSE GUI */
2113 if (!compose->use_attach) {
2114 GtkItemFactory *ifactory;
2115 GtkWidget *menuitem;
2117 ifactory = gtk_item_factory_from_widget(compose->menubar);
2118 menuitem = gtk_item_factory_get_item(ifactory,
2119 "/View/Attachment");
2120 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2124 ainfo = g_new0(AttachInfo, 1);
2125 ainfo->file = g_strdup(file);
2127 if (cnttype == MIME_MESSAGE_RFC822) {
2128 ainfo->content_type = g_strdup("message/rfc822");
2129 ainfo->encoding = ENC_7BIT;
2130 ainfo->name = g_strdup_printf(_("Message: %s"),
2133 ainfo->content_type = procmime_get_mime_type(file);
2134 if (!ainfo->content_type)
2135 ainfo->content_type =
2136 g_strdup("application/octet-stream");
2137 ainfo->encoding = ENC_BASE64;
2138 ainfo->name = g_strdup(g_basename(file));
2142 compose_attach_info(compose, ainfo, cnttype);
2145 #define GET_CHAR(pos, buf, len) \
2147 if (text->use_wchar) \
2148 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2150 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2155 static void compose_wrap_line(Compose *compose)
2157 GtkSText *text = GTK_STEXT(compose->text);
2158 gint ch_len, last_ch_len;
2159 gchar cbuf[MB_LEN_MAX], last_ch;
2163 gint p_start, p_end;
2164 gint line_pos, cur_pos;
2165 gint line_len, cur_len;
2167 gtk_stext_freeze(text);
2169 text_len = gtk_stext_get_length(text);
2171 /* check to see if the point is on the paragraph mark (empty line). */
2172 cur_pos = gtk_stext_get_point(text);
2173 GET_CHAR(cur_pos, cbuf, ch_len);
2174 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2176 goto compose_end; /* on the paragraph mark */
2177 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2178 if (ch_len == 1 && *cbuf == '\n')
2179 goto compose_end; /* on the paragraph mark */
2182 /* find paragraph start. */
2183 line_end = quoted = 0;
2184 for (p_start = cur_pos; p_start >= 0; --p_start) {
2185 GET_CHAR(p_start, cbuf, ch_len);
2186 if (ch_len == 1 && *cbuf == '\n') {
2188 goto compose_end; /* quoted part */
2195 if (ch_len == 1 && strchr(">:#", *cbuf))
2197 else if (ch_len != 1 || !isspace(*cbuf))
2206 /* find paragraph end. */
2208 for (p_end = cur_pos; p_end < text_len; p_end++) {
2209 GET_CHAR(p_end, cbuf, ch_len);
2210 if (ch_len == 1 && *cbuf == '\n') {
2217 if (line_end && ch_len == 1 && strchr(">:#", *cbuf))
2218 goto compose_end; /* quoted part */
2223 if (p_end >= text_len)
2226 if (p_start >= p_end)
2229 line_len = cur_len = 0;
2233 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2236 GET_CHAR(cur_pos, cbuf, ch_len);
2243 if (ch_len == 1 && isspace(*cbuf))
2246 if (ch_len == 1 && *cbuf == '\n') {
2248 if (last_ch_len == 1 && !isspace(last_ch)) {
2249 if (cur_pos + 1 < p_end) {
2250 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2251 if (ch_len == 1 && !isspace(*cbuf))
2255 gtk_stext_set_point(text, cur_pos + 1);
2256 gtk_stext_backward_delete(text, 1);
2258 gtk_stext_set_point(text, cur_pos);
2259 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2269 last_ch_len = ch_len;
2273 line_pos = cur_pos + 1;
2274 line_len = cur_len + ch_len;
2277 if (cur_len + ch_len > prefs_common.linewrap_len &&
2281 GET_CHAR(line_pos - 1, cbuf, ch_len);
2282 if (ch_len == 1 && isspace(*cbuf)) {
2283 gtk_stext_set_point(text, line_pos);
2284 gtk_stext_backward_delete(text, 1);
2293 gtk_stext_set_point(text, line_pos);
2294 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2298 cur_len = cur_len - line_len + ch_len;
2304 line_pos = cur_pos + 1;
2305 line_len = cur_len + ch_len;
2311 gtk_stext_thaw(text);
2314 /* return indent length */
2315 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2317 gint indent_len = 0;
2319 gchar cbuf[MB_LEN_MAX];
2321 for (i = start_pos; i < text_len; i++) {
2322 GET_CHAR(i, cbuf, ch_len);
2325 /* allow space, tab, > or | */
2326 if (cbuf[0] != ' ' && cbuf[0] != '\t' &&
2327 cbuf[0] != '>' && cbuf[0] != '|')
2335 /* insert quotation string when line was wrapped */
2336 static guint ins_quote(GtkSText *text, guint quote_len, guint indent_len,
2337 guint prev_line_pos, guint text_len,
2344 for (i = 0; i < indent_len; i++) {
2345 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2346 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2348 ins_len = indent_len;
2350 gtk_stext_insert(text, NULL, NULL, NULL, quote_fmt, quote_len);
2351 ins_len = quote_len;
2359 /* Darko: used when I debug wrapping */
2360 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2365 printf("%d [", pos);
2366 for (i = pos; i < tlen; i++) {
2367 ch = GTK_STEXT_INDEX(text, i);
2368 if (breakoncr && ch == '\n')
2376 static void compose_wrap_line_all(Compose *compose)
2378 GtkSText *text = GTK_STEXT(compose->text);
2380 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2381 gint line_len = 0, cur_len = 0;
2383 gboolean is_new_line = TRUE, do_delete = FALSE;
2384 guint qlen = 0, i_len = 0;
2385 gboolean linewrap_quote = TRUE;
2386 guint linewrap_len = prefs_common.linewrap_len;
2387 gchar *qfmt = prefs_common.quotemark;
2388 gchar cbuf[MB_LEN_MAX];
2390 gtk_stext_freeze(text);
2392 /* make text buffer contiguous */
2393 /* gtk_stext_compact_buffer(text); */
2395 tlen = gtk_stext_get_length(text);
2397 for (; cur_pos < tlen; cur_pos++) {
2398 /* mark position of new line - needed for quotation wrap */
2400 if (linewrap_quote) {
2401 qlen = gtkut_stext_str_compare
2402 (text, cur_pos, tlen, qfmt);
2404 i_len = get_indent_length
2405 (text, cur_pos, tlen);
2409 is_new_line = FALSE;
2412 printf("new line i_len=%d qlen=%d p_pos=", i_len, qlen);
2413 dump_text(text, p_pos, tlen, 1);
2417 GET_CHAR(cur_pos, cbuf, ch_len);
2419 /* fix line length for tabs */
2420 if (ch_len == 1 && *cbuf == '\t') {
2421 guint tab_width = text->default_tab_width;
2422 guint tab_offset = line_len % tab_width;
2425 printf("found tab at pos=%d line_len=%d ", cur_pos,
2429 line_len += tab_width - tab_offset - 1;
2433 printf("new_len=%d\n", line_len);
2437 /* we have encountered line break */
2438 if (ch_len == 1 && *cbuf == '\n') {
2441 gchar cb[MB_CUR_MAX];
2444 printf("found CR at %d next line is ", cur_pos);
2445 dump_text(text, cur_pos + 1, tlen, 1);
2447 /* if it's just quotation + newline skip it */
2448 if (i_len && (cur_pos + 1 < tlen)) {
2449 /* check if text at new line matches indent */
2450 ilen = gtkut_stext_str_compare_n
2451 (text, cur_pos + 1, p_pos, i_len, tlen);
2452 if (cur_pos + ilen < tlen) {
2453 GET_CHAR(cur_pos + ilen + 1, cb, clen);
2454 /* no need to join the lines */
2455 if (clen == 1 && cb[0] == '\n')
2458 /* if it's just newline skip it */
2459 } else if (do_delete && (cur_pos + 1 < tlen)) {
2460 GET_CHAR(cur_pos + 1, cb, clen);
2461 /* no need to join the lines */
2462 if (clen == 1 && cb[0] == '\n')
2466 /* skip delete if it is continuous URL */
2467 if (do_delete && (line_pos - p_pos <= i_len) &&
2468 gtkut_stext_is_uri_string(text, line_pos, tlen))
2472 printf("qlen=%d l_len=%d wrap_len=%d do_del=%d\n",
2473 qlen, line_len, linewrap_len, do_delete);
2475 /* should we delete to perform smart wrapping */
2476 if (line_len < linewrap_len && do_delete) {
2477 /* get rid of newline */
2478 gtk_stext_set_point(text, cur_pos);
2479 gtk_stext_forward_delete(text, 1);
2482 /* if text starts with quote fmt or with
2483 indent string, delete them */
2485 ilen = gtkut_stext_str_compare_n
2486 (text, cur_pos, p_pos, i_len,
2489 gtk_stext_forward_delete
2494 if (gtkut_stext_str_compare
2495 (text, cur_pos, tlen, qfmt)) {
2496 gtk_stext_forward_delete
2502 GET_CHAR(cur_pos, cb, clen);
2504 /* insert space if it's alphanumeric */
2505 if ((cur_pos != line_pos) &&
2506 ((clen > 1) || isalnum(cb[0]))) {
2507 gtk_stext_insert(text, NULL, NULL,
2509 /* gtk_stext_compact_buffer(text); */
2513 /* and start over with current line */
2514 cur_pos = p_pos - 1;
2516 line_len = cur_len = 0;
2521 printf("after delete l_pos=");
2522 dump_text(text, line_pos, tlen, 1);
2527 /* mark new line beginning */
2528 line_pos = cur_pos + 1;
2529 line_len = cur_len = 0;
2541 /* possible line break */
2542 if (ch_len == 1 && isspace(*cbuf)) {
2543 line_pos = cur_pos + 1;
2544 line_len = cur_len + ch_len;
2547 /* are we over wrapping length set in preferences ? */
2548 if (cur_len + ch_len > linewrap_len) {
2552 printf("should wrap cur_pos=%d ", cur_pos);
2553 dump_text(text, p_pos, tlen, 1);
2554 dump_text(text, line_pos, tlen, 1);
2556 /* force wrapping if it is one long word but not URL */
2557 if (line_pos - p_pos <= i_len)
2558 if (!gtkut_stext_is_uri_string
2559 (text, line_pos, tlen))
2560 line_pos = cur_pos - 1;
2562 printf("new line_pos=%d\n", line_pos);
2565 GET_CHAR(line_pos - 1, cbuf, clen);
2567 /* if next character is space delete it */
2568 if (clen == 1 && isspace(*cbuf)) {
2569 if (p_pos + i_len != line_pos ||
2570 !gtkut_stext_is_uri_string
2571 (text, line_pos, tlen)) {
2572 gtk_stext_set_point(text, line_pos);
2573 gtk_stext_backward_delete(text, 1);
2582 /* if it is URL at beginning of line don't wrap */
2583 if (p_pos + i_len == line_pos &&
2584 gtkut_stext_is_uri_string(text, line_pos, tlen)) {
2586 printf("found URL at ");
2587 dump_text(text, line_pos, tlen, 1);
2593 gtk_stext_set_point(text, line_pos);
2594 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2595 /* gtk_stext_compact_buffer(text); */
2598 /* for loop will increase it */
2599 cur_pos = line_pos - 1;
2600 /* start over with current line */
2606 printf("after CR insert ");
2607 dump_text(text, line_pos, tlen, 1);
2608 dump_text(text, cur_pos, tlen, 1);
2611 /* should we insert quotation ? */
2612 if (linewrap_quote && qlen) {
2613 /* only if line is not already quoted */
2614 if (!gtkut_stext_str_compare
2615 (text, line_pos, tlen, qfmt)) {
2618 if (line_pos - p_pos > i_len) {
2623 /* gtk_stext_compact_buffer(text); */
2627 printf("after quote insert ");
2628 dump_text(text, line_pos, tlen, 1);
2636 line_pos = cur_pos + 1;
2637 line_len = cur_len + ch_len;
2639 /* advance to next character in buffer */
2643 gtk_stext_thaw(text);
2648 static void compose_set_title(Compose *compose)
2653 edited = compose->modified ? _(" [Edited]") : "";
2654 if (compose->account && compose->account->address)
2655 str = g_strdup_printf(_("%s - Compose message%s"),
2656 compose->account->address, edited);
2658 str = g_strdup_printf(_("Compose message%s"), edited);
2659 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2664 * compose_current_mail_account:
2666 * Find a current mail account (the currently selected account, or the
2667 * default account, if a news account is currently selected). If a
2668 * mail account cannot be found, display an error message.
2670 * Return value: Mail account, or NULL if not found.
2672 static PrefsAccount *
2673 compose_current_mail_account(void)
2677 if (cur_account && cur_account->protocol != A_NNTP)
2680 ac = account_get_default();
2681 if (!ac || ac->protocol == A_NNTP) {
2682 alertpanel_error(_("Account for sending mail is not specified.\n"
2683 "Please select a mail account before sending."));
2690 gboolean compose_check_for_valid_recipient(Compose *compose) {
2691 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2692 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2693 gboolean recipient_found = FALSE;
2697 /* free to and newsgroup list */
2698 slist_free_strings(compose->to_list);
2699 g_slist_free(compose->to_list);
2700 compose->to_list = NULL;
2702 slist_free_strings(compose->newsgroup_list);
2703 g_slist_free(compose->newsgroup_list);
2704 compose->newsgroup_list = NULL;
2706 /* search header entries for to and newsgroup entries */
2707 for(list = compose->header_list; list; list = list->next) {
2710 header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
2711 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2713 if(entry[0] != '\0') {
2714 for(strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2715 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2716 compose->to_list = address_list_append(compose->to_list, entry);
2717 recipient_found = TRUE;
2720 for(strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2721 if(!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2722 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2723 recipient_found = TRUE;
2729 return recipient_found;
2732 gint compose_send(Compose *compose)
2738 val = compose_queue(compose, &msgnum, &folder);
2740 alertpanel_error(_("Could not queue message for sending"));
2744 val = procmsg_send_message_queue(folder_item_fetch_msg(folder, msgnum));
2746 folder_item_remove_msg(folder, msgnum);
2747 folderview_update_item(folder, TRUE);
2753 #if 0 /* compose restructure */
2754 gint compose_send(Compose *compose)
2756 gchar tmp[MAXPATHLEN + 1];
2758 static gboolean lock = FALSE;
2762 g_return_val_if_fail(compose->account != NULL, -1);
2763 g_return_val_if_fail(compose->orig_account != NULL, -1);
2767 if(!compose_check_for_valid_recipient(compose)) {
2768 alertpanel_error(_("Recipient is not specified."));
2773 /* write to temporary file */
2774 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
2775 get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
2777 if (prefs_common.linewrap_at_send)
2778 compose_wrap_line_all(compose);
2780 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2785 if (!compose->to_list && !compose->newsgroup_list) {
2786 g_warning(_("can't get recipient list."));
2792 if (compose->to_list) {
2795 #if 0 /* NEW COMPOSE GUI */
2796 if (compose->account->protocol != A_NNTP)
2797 ac = compose->account;
2798 else if (compose->orig_account->protocol != A_NNTP)
2799 ac = compose->orig_account;
2800 else if (cur_account && cur_account->protocol != A_NNTP)
2803 ac = compose_current_mail_account();
2811 ac = compose->account;
2813 ok = send_message(tmp, ac, compose->to_list);
2814 statusbar_pop_all();
2817 if (ok == 0 && compose->newsgroup_list) {
2820 if (compose->account->protocol == A_NNTP)
2821 folder = FOLDER(compose->account->folder);
2823 folder = FOLDER(compose->orig_account->folder);
2825 ok = news_post(folder, tmp);
2827 alertpanel_error(_("Error occurred while posting the message to %s ."),
2828 compose->account->nntp_server);
2835 /* queue message if failed to send */
2837 if (prefs_common.queue_msg) {
2842 _("Error occurred while sending the message.\n"
2843 "Put this message into queue folder?"),
2844 _("OK"), _("Cancel"), NULL);
2845 if (G_ALERTDEFAULT == val) {
2846 ok = compose_queue(compose, tmp);
2848 alertpanel_error(_("Can't queue the message."));
2851 alertpanel_error(_("Error occurred while sending the message."));
2853 if (compose->mode == COMPOSE_REEDIT) {
2854 compose_remove_reedit_target(compose);
2855 if (compose->targetinfo)
2856 folderview_update_item
2857 (compose->targetinfo->folder, TRUE);
2861 /* save message to outbox */
2862 if (ok == 0 && prefs_common.savemsg) {
2863 if (compose_save_to_outbox(compose, tmp) < 0)
2865 (_("Can't save the message to outbox."));
2874 static gboolean compose_use_attach(Compose *compose) {
2875 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2878 static gint compose_bounce_write_headers_from_headerlist(Compose *compose,
2881 gchar buf[BUFFSIZE];
2883 gboolean first_address;
2885 ComposeHeaderEntry *headerentry;
2886 gchar *headerentryname;
2887 gchar *header_w_colon;
2891 debug_print(_("Writing bounce header\n"));
2893 header_w_colon = g_strconcat("To:", NULL);
2894 to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2895 header_w_colon = g_strconcat("Cc:", NULL);
2896 cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
2898 first_address = TRUE;
2899 for(list = compose->header_list; list; list = list->next) {
2900 headerentry = ((ComposeHeaderEntry *)list->data);
2901 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2903 if(g_strcasecmp(headerentryname, cc_hdr) == 0
2904 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2905 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2906 Xstrdup_a(str, str, return -1);
2908 if(str[0] != '\0') {
2909 compose_convert_header
2910 (buf, sizeof(buf), str,
2911 strlen("Resent-To") + 2);
2913 fprintf(fp, "Resent-To: ");
2914 first_address = FALSE;
2918 fprintf(fp, "%s", buf);
2922 /* if(!first_address) { */
2929 static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
2931 gchar buf[BUFFSIZE];
2933 /* struct utsname utsbuf; */
2935 g_return_val_if_fail(fp != NULL, -1);
2936 g_return_val_if_fail(compose->account != NULL, -1);
2937 g_return_val_if_fail(compose->account->address != NULL, -1);
2940 get_rfc822_date(buf, sizeof(buf));
2941 fprintf(fp, "Resent-Date: %s\n", buf);
2944 if (compose->account->name && *compose->account->name) {
2945 compose_convert_header
2946 (buf, sizeof(buf), compose->account->name,
2948 fprintf(fp, "Resent-From: %s <%s>\n",
2949 buf, compose->account->address);
2951 fprintf(fp, "Resent-From: %s\n", compose->account->address);
2954 compose_bounce_write_headers_from_headerlist(compose, fp);
2956 /* separator between header and body */
2962 static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
2967 gchar buf[BUFFSIZE];
2969 if ((fp = fopen(compose->bounce_filename, "r")) == NULL) {
2970 FILE_OP_ERROR(file, "fopen");
2974 if ((fdest = fopen(file, "w")) == NULL) {
2975 FILE_OP_ERROR(file, "fopen");
2980 /* chmod for security */
2981 if (change_file_mode_rw(fdest, file) < 0) {
2982 FILE_OP_ERROR(file, "chmod");
2983 g_warning(_("can't change file mode\n"));
2986 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
2987 /* should filter returnpath, delivered-to */
2988 if ((g_strncasecmp(buf, "Return-Path:",
2989 strlen("Return-Path:")) == 0)
2990 || (g_strncasecmp(buf, "Delivered-To:",
2991 strlen("Delivered-To:")) == 0))
2994 if (fputs(buf, fdest) == -1)
2997 if (g_strncasecmp(buf, "From:", strlen("From:")) == 0) {
2998 fputs(" (by way of ", fdest);
2999 if (compose->account->name
3000 && *compose->account->name) {
3001 compose_convert_header
3003 compose->account->name,
3005 fprintf(fdest, "%s <%s>",
3006 buf, compose->account->address);
3008 fprintf(fdest, "%s",
3009 compose->account->address);
3013 if (fputs("\n", fdest) == -1)
3017 compose_bounce_write_headers(compose, fdest);
3019 while ((len = fread(buf, sizeof(gchar), BUFFSIZE, fp)) > 0) {
3020 if (fwrite(buf, sizeof(gchar), len, fdest) == -1)
3038 * interfaces to rfc2015 to keep out the prefs stuff there.
3039 * returns 0 on success and -1 on error. */
3040 static int compose_create_signers_list (Compose *compose, GSList **pkey_list)
3042 const char *keyid = NULL;
3045 switch (compose->account->sign_key) {
3046 case SIGN_KEY_DEFAULT:
3048 return 0; /* nothing to do */
3050 case SIGN_KEY_BY_FROM:
3051 keyid = compose->account->address;
3054 case SIGN_KEY_CUSTOM:
3055 keyid = compose->account->sign_key_id;
3059 g_assert_not_reached ();
3062 key_list = rfc2015_create_signers_list(keyid);
3065 alertpanel_error("Could not find any key associated with currently "
3066 "selected keyid `%s'!", keyid);
3070 *pkey_list = key_list;
3073 #endif /* USE_GPGME */
3075 static gint compose_write_to_file(Compose *compose, const gchar *file,
3082 const gchar *out_codeset;
3083 EncodingType encoding;
3085 if ((fp = fopen(file, "w")) == NULL) {
3086 FILE_OP_ERROR(file, "fopen");
3090 /* chmod for security */
3091 if (change_file_mode_rw(fp, file) < 0) {
3092 FILE_OP_ERROR(file, "chmod");
3093 g_warning(_("can't change file mode\n"));
3096 /* get all composed text */
3097 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3098 len = strlen(chars);
3099 if (is_ascii_str(chars)) {
3100 buf = g_strdup(chars);
3101 out_codeset = CS_US_ASCII;
3102 encoding = ENC_7BIT;
3104 const gchar *src_codeset;
3106 out_codeset = conv_get_outgoing_charset_str();
3107 if (!strcasecmp(out_codeset, CS_US_ASCII))
3108 out_codeset = CS_ISO_8859_1;
3109 encoding = procmime_get_encoding_for_charset(out_codeset);
3111 src_codeset = conv_get_current_charset_str();
3112 /* if current encoding is US-ASCII, set it the same as
3113 outgoing one to prevent code conversion failure */
3114 if (!strcasecmp(src_codeset, CS_US_ASCII))
3115 src_codeset = out_codeset;
3117 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3118 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3120 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3125 alertpanel_error(_("Can't convert the codeset of the message."));
3132 if (compose_write_headers
3133 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3134 g_warning(_("can't write headers\n"));
3141 if (compose_use_attach(compose)) {
3143 /* This prolog message is ignored by mime software and
3144 * because it would make our signing/encryption task
3145 * tougher, we don't emit it in that case */
3146 if (!compose->use_signing && !compose->use_encryption)
3148 fputs("This is a multi-part message in MIME format.\n", fp);
3150 fprintf(fp, "\n--%s\n", compose->boundary);
3151 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3153 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3154 procmime_get_encoding_str(encoding));
3160 if (encoding == ENC_BASE64) {
3161 gchar outbuf[B64_BUFFSIZE];
3164 for (i = 0; i < len; i += B64_LINE_SIZE) {
3165 l = MIN(B64_LINE_SIZE, len - i);
3166 to64frombits(outbuf, buf + i, l);
3170 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3171 FILE_OP_ERROR(file, "fwrite");
3179 if (compose_use_attach(compose))
3180 compose_write_attach(compose, fp);
3182 if (fclose(fp) == EOF) {
3183 FILE_OP_ERROR(file, "fclose");
3189 if (compose->use_signing) {
3192 if (compose_create_signers_list(compose, &key_list) == -1 ||
3193 rfc2015_sign(file, key_list) < 0) {
3199 if (compose->use_encryption) {
3200 if (rfc2015_encrypt(file, compose->to_list, compose->account->ascii_armored) < 0) {
3205 #endif /* USE_GPGME */
3210 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3216 if ((fp = fopen(file, "w")) == NULL) {
3217 FILE_OP_ERROR(file, "fopen");
3221 /* chmod for security */
3222 if (change_file_mode_rw(fp, file) < 0) {
3223 FILE_OP_ERROR(file, "chmod");
3224 g_warning(_("can't change file mode\n"));
3227 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3230 len = strlen(chars);
3231 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3232 FILE_OP_ERROR(file, "fwrite");
3241 if (fclose(fp) == EOF) {
3242 FILE_OP_ERROR(file, "fclose");
3249 static gint compose_save_to_outbox(Compose *compose, const gchar *file)
3256 debug_print(_("saving sent message...\n"));
3258 outbox = folder_get_default_outbox();
3259 path = folder_item_get_path(outbox);
3260 if (!is_dir_exist(path))
3261 make_dir_hier(path);
3263 folder_item_scan(outbox);
3264 if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
3266 g_warning(_("can't save message\n"));
3270 if ((fp = procmsg_open_mark_file(path, TRUE)) == NULL)
3271 g_warning(_("can't open mark file\n"));
3275 newmsginfo.msgnum = num;
3276 newmsginfo.flags.perm_flags = 0;
3277 newmsginfo.flags.tmp_flags = 0;
3278 procmsg_write_flags(&newmsginfo, fp);
3286 static gint compose_remove_reedit_target(Compose *compose)
3289 MsgInfo *msginfo = compose->targetinfo;
3291 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3292 if (!msginfo) return -1;
3294 item = msginfo->folder;
3295 g_return_val_if_fail(item != NULL, -1);
3297 folder_item_scan(item);
3298 if (procmsg_msg_exist(msginfo) &&
3299 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3300 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3301 g_warning(_("can't remove the old message\n"));
3310 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3313 gchar *tmp, *tmp2, *queue_path;
3316 gchar buf[BUFFSIZE];
3318 static gboolean lock = FALSE;
3319 PrefsAccount *mailac = NULL, *newsac = NULL;
3321 debug_print(_("queueing message...\n"));
3322 g_return_val_if_fail(compose->account != NULL, -1);
3323 g_return_val_if_fail(compose->orig_account != NULL, -1);
3327 if(!compose_check_for_valid_recipient(compose)) {
3328 alertpanel_error(_("Recipient is not specified."));
3333 if (!compose->to_list && !compose->newsgroup_list) {
3334 g_warning(_("can't get recipient list."));
3339 if(compose->to_list) {
3340 if (compose->account->protocol != A_NNTP)
3341 mailac = compose->account;
3342 else if (compose->orig_account->protocol != A_NNTP)
3343 mailac = compose->orig_account;
3344 else if (cur_account && cur_account->protocol != A_NNTP)
3345 mailac = cur_account;
3346 else if (!(mailac = compose_current_mail_account())) {
3348 alertpanel_error(_("No account for sending mails available!"));
3353 if(compose->newsgroup_list) {
3354 if (compose->account->protocol == A_NNTP)
3355 newsac = compose->account;
3356 else if(!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3358 alertpanel_error(_("No account for posting news available!"));
3363 if (prefs_common.linewrap_at_send)
3364 compose_wrap_line_all(compose);
3366 /* write to temporary file */
3367 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3368 G_DIR_SEPARATOR, (gint)compose);
3370 if (compose->bounce_filename != NULL) {
3371 if (compose_bounce_write_to_file(compose, tmp2) < 0) {
3378 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3385 /* add queue header */
3386 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3387 G_DIR_SEPARATOR, (gint)compose);
3388 if ((fp = fopen(tmp, "w")) == NULL) {
3389 FILE_OP_ERROR(tmp, "fopen");
3393 if ((src_fp = fopen(tmp2, "r")) == NULL) {
3394 FILE_OP_ERROR(tmp2, "fopen");
3402 if (change_file_mode_rw(fp, tmp) < 0) {
3403 FILE_OP_ERROR(tmp, "chmod");
3404 g_warning(_("can't change file mode\n"));
3407 /* queueing variables */
3408 fprintf(fp, "AF:\n");
3409 fprintf(fp, "NF:0\n");
3410 fprintf(fp, "PS:10\n");
3411 fprintf(fp, "SRH:1\n");
3412 fprintf(fp, "SFN:\n");
3413 fprintf(fp, "DSR:\n");
3415 fprintf(fp, "MID:<%s>\n", compose->msgid);
3417 fprintf(fp, "MID:\n");
3418 fprintf(fp, "CFG:\n");
3419 fprintf(fp, "PT:0\n");
3420 fprintf(fp, "S:%s\n", compose->account->address);
3421 fprintf(fp, "RQ:\n");
3423 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3425 fprintf(fp, "SSV:\n");
3427 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3429 fprintf(fp, "NSV:\n");
3430 fprintf(fp, "SSH:\n");
3431 /* write recepient list */
3433 if(compose->to_list) {
3434 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3435 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3436 fprintf(fp, ",<%s>", (gchar *)cur->data);
3439 /* write newsgroup list */
3441 if(compose->newsgroup_list) {
3442 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3443 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3444 fprintf(fp, ",%s", (gchar *)cur->data);
3447 /* Sylpheed account IDs */
3449 fprintf(fp, "MAID:%d\n", mailac->account_id);
3452 fprintf(fp, "NAID:%d\n", newsac->account_id);
3454 /* Save copy folder */
3455 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3458 str = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3459 fprintf(fp, "SCF:%s\n", str);
3464 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3465 if (fputs(buf, fp) == EOF) {
3466 FILE_OP_ERROR(tmp, "fputs");
3477 if (fclose(fp) == EOF) {
3478 FILE_OP_ERROR(tmp, "fclose");
3487 queue = folder_get_default_queue();
3489 folder_item_scan(queue);
3490 queue_path = folder_item_get_path(queue);
3491 if (!is_dir_exist(queue_path))
3492 make_dir_hier(queue_path);
3493 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3494 g_warning(_("can't queue the message\n"));
3505 if (compose->mode == COMPOSE_REEDIT) {
3506 compose_remove_reedit_target(compose);
3507 if (compose->targetinfo &&
3508 compose->targetinfo->folder != queue)
3509 folderview_update_item
3510 (compose->targetinfo->folder, TRUE);
3513 if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
3514 g_warning(_("can't open mark file\n"));
3518 newmsginfo.msgnum = num;
3519 newmsginfo.flags.perm_flags = 0;
3520 newmsginfo.flags.tmp_flags = 0;
3521 procmsg_write_flags(&newmsginfo, fp);
3526 folder_item_scan(queue);
3527 folderview_update_item(queue, TRUE);
3529 if((msgnum != NULL) && (item != NULL)) {
3537 static void compose_write_attach(Compose *compose, FILE *fp)
3540 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3543 gchar filename[BUFFSIZE];
3546 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3548 if ((attach_fp = fopen(ainfo->file, "r")) == NULL) {
3549 g_warning(_("Can't open file %s\n"), ainfo->file);
3553 fprintf(fp, "\n--%s\n", compose->boundary);
3555 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3556 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3557 fprintf(fp, "Content-Disposition: inline\n");
3559 conv_encode_header(filename, sizeof(filename),
3561 fprintf(fp, "Content-Type: %s;\n"
3563 ainfo->content_type, filename);
3564 fprintf(fp, "Content-Disposition: attachment;\n"
3565 " filename=\"%s\"\n", filename);
3568 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3569 procmime_get_encoding_str(ainfo->encoding));
3571 if (ainfo->encoding == ENC_7BIT) {
3572 gchar buf[BUFFSIZE];
3574 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3579 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3581 while ((len = fread(inbuf, sizeof(gchar),
3582 B64_LINE_SIZE, attach_fp))
3584 to64frombits(outbuf, inbuf, B64_LINE_SIZE);
3588 if (len > 0 && feof(attach_fp)) {
3589 to64frombits(outbuf, inbuf, len);
3598 fprintf(fp, "\n--%s--\n", compose->boundary);
3601 #define IS_IN_CUSTOM_HEADER(header) \
3602 (compose->account->add_customhdr && \
3603 custom_header_find(compose->account->customhdr_list, header) != NULL)
3605 static gint compose_write_headers_from_headerlist(Compose *compose,
3609 gchar buf[BUFFSIZE];
3610 gchar *str, *header_w_colon, *trans_hdr;
3611 gboolean first_address;
3613 ComposeHeaderEntry *headerentry;
3614 gchar * headerentryname;
3616 if (IS_IN_CUSTOM_HEADER(header)) {
3620 debug_print(_("Writing %s-header\n"), header);
3622 header_w_colon = g_strconcat(header, ":", NULL);
3623 trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
3625 first_address = TRUE;
3626 for(list = compose->header_list; list; list = list->next) {
3627 headerentry = ((ComposeHeaderEntry *)list->data);
3628 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3630 if(!g_strcasecmp(trans_hdr, headerentryname)) {
3631 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3632 Xstrdup_a(str, str, return -1);
3634 if(str[0] != '\0') {
3635 compose_convert_header
3636 (buf, sizeof(buf), str,
3637 strlen(header) + 2);
3639 fprintf(fp, "%s: ", header);
3640 first_address = FALSE;
3644 fprintf(fp, "%s", buf);
3648 if(!first_address) {
3652 g_free(header_w_colon);
3657 static gint compose_write_headers(Compose *compose, FILE *fp,
3658 const gchar *charset, EncodingType encoding,
3661 gchar buf[BUFFSIZE];
3663 /* struct utsname utsbuf; */
3665 g_return_val_if_fail(fp != NULL, -1);
3666 g_return_val_if_fail(charset != NULL, -1);
3667 g_return_val_if_fail(compose->account != NULL, -1);
3668 g_return_val_if_fail(compose->account->address != NULL, -1);
3671 if (compose->account->add_date) {
3672 get_rfc822_date(buf, sizeof(buf));
3673 fprintf(fp, "Date: %s\n", buf);
3677 if (!IS_IN_CUSTOM_HEADER("From")) {
3678 if (compose->account->name && *compose->account->name) {
3679 compose_convert_header
3680 (buf, sizeof(buf), compose->account->name,
3682 fprintf(fp, "From: %s <%s>\n",
3683 buf, compose->account->address);
3685 fprintf(fp, "From: %s\n", compose->account->address);
3689 compose_write_headers_from_headerlist(compose, fp, "To");
3690 #if 0 /* NEW COMPOSE GUI */
3691 if (compose->use_to) {
3692 str = gtk_entry_get_text(GTK_ENTRY(compose->to_entry));
3694 Xstrdup_a(str, str, return -1);
3697 compose->to_list = address_list_append
3698 (compose->to_list, str);
3699 if (!IS_IN_CUSTOM_HEADER("To")) {
3700 compose_convert_header
3701 (buf, sizeof(buf), str,
3703 fprintf(fp, "To: %s\n", buf);
3711 compose_write_headers_from_headerlist(compose, fp, "Newsgroups");
3712 #if 0 /* NEW COMPOSE GUI */
3713 str = gtk_entry_get_text(GTK_ENTRY(compose->newsgroups_entry));
3715 Xstrdup_a(str, str, return -1);
3719 compose->newsgroup_list =
3720 newsgroup_list_append(compose->newsgroup_list,
3722 if (!IS_IN_CUSTOM_HEADER("Newsgroups")) {
3723 compose_convert_header(buf, sizeof(buf), str,
3724 strlen("Newsgroups: "));
3725 fprintf(fp, "Newsgroups: %s\n", buf);
3731 compose_write_headers_from_headerlist(compose, fp, "Cc");
3732 #if 0 /* NEW COMPOSE GUI */
3733 if (compose->use_cc) {
3734 str = gtk_entry_get_text(GTK_ENTRY(compose->cc_entry));
3736 Xstrdup_a(str, str, return -1);
3739 compose->to_list = address_list_append
3740 (compose->to_list, str);
3741 if (!IS_IN_CUSTOM_HEADER("Cc")) {
3742 compose_convert_header
3743 (buf, sizeof(buf), str,
3745 fprintf(fp, "Cc: %s\n", buf);
3752 compose_write_headers_from_headerlist(compose, fp, "Bcc");
3753 #if 0 /* NEW COMPOSE GUI */
3754 if (compose->use_bcc) {
3755 str = gtk_entry_get_text(GTK_ENTRY(compose->bcc_entry));
3757 Xstrdup_a(str, str, return -1);
3760 compose->to_list = address_list_append
3761 (compose->to_list, str);
3762 compose_convert_header(buf, sizeof(buf), str,
3764 fprintf(fp, "Bcc: %s\n", buf);