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"
87 #include "prefs_actions.h"
90 #include "procheader.h"
92 #include "statusbar.h"
99 #include "alertpanel.h"
100 #include "manage_window.h"
101 #include "gtkshruler.h"
103 #include "addr_compl.h"
104 #include "quote_fmt.h"
105 #include "template.h"
107 #include "foldersel.h"
111 # include "rfc2015.h"
121 #define N_ATTACH_COLS 3
125 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
126 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
127 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
128 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
129 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
130 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
131 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
132 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
133 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
134 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
135 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
136 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
137 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
138 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
139 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END
140 } ComposeCallGtkSTextAction;
144 PRIORITY_HIGHEST = 1,
151 #define B64_LINE_SIZE 57
152 #define B64_BUFFSIZE 77
154 #define MAX_REFERENCES_LEN 999
156 static GdkColor quote_color = {0, 0, 0, 0xbfff};
158 static GList *compose_list = NULL;
160 Compose *compose_generic_new (PrefsAccount *account,
163 GPtrArray *attach_files);
165 static Compose *compose_create (PrefsAccount *account,
167 static void compose_toolbar_create (Compose *compose,
168 GtkWidget *container);
169 static void compose_toolbar_update (Compose *compose);
171 static GtkWidget *compose_account_option_menu_create
173 static void compose_set_template_menu (Compose *compose);
174 static void compose_template_apply (Compose *compose,
177 static void compose_destroy (Compose *compose);
179 static void compose_entries_set (Compose *compose,
180 const gchar *mailto);
181 static gint compose_parse_header (Compose *compose,
183 static gchar *compose_parse_references (const gchar *ref,
186 static gchar *compose_quote_fmt (Compose *compose,
192 static void compose_reply_set_entry (Compose *compose,
197 followup_and_reply_to);
198 static void compose_reedit_set_entry (Compose *compose,
200 static void compose_insert_sig (Compose *compose);
201 static void compose_insert_file (Compose *compose,
203 static void compose_attach_append (Compose *compose,
206 const gchar *content_type);
207 static void compose_attach_parts (Compose *compose,
209 static void compose_wrap_line (Compose *compose);
210 static void compose_wrap_line_all (Compose *compose);
211 static void compose_wrap_line_all_full (Compose *compose,
213 static void compose_set_title (Compose *compose);
214 static void compose_select_account (Compose *compose,
215 PrefsAccount *account);
217 static PrefsAccount *compose_current_mail_account(void);
218 /* static gint compose_send (Compose *compose); */
219 static gboolean compose_check_for_valid_recipient
221 static gboolean compose_check_entries (Compose *compose,
222 gboolean check_subject);
223 static gint compose_write_to_file (Compose *compose,
226 static gint compose_write_body_to_file (Compose *compose,
228 static gint compose_remove_reedit_target (Compose *compose);
229 void compose_remove_draft (Compose *compose);
230 static gint compose_queue (Compose *compose,
233 static gint compose_queue_sub (Compose *compose,
236 gboolean check_subject);
237 static void compose_write_attach (Compose *compose,
239 static gint compose_write_headers (Compose *compose,
241 const gchar *charset,
242 EncodingType encoding,
245 static void compose_convert_header (gchar *dest,
249 static void compose_generate_msgid (Compose *compose,
253 static void compose_attach_info_free (AttachInfo *ainfo);
254 static void compose_attach_remove_selected (Compose *compose);
256 static void compose_attach_property (Compose *compose);
257 static void compose_attach_property_create (gboolean *cancelled);
258 static void attach_property_ok (GtkWidget *widget,
259 gboolean *cancelled);
260 static void attach_property_cancel (GtkWidget *widget,
261 gboolean *cancelled);
262 static gint attach_property_delete_event (GtkWidget *widget,
264 gboolean *cancelled);
265 static void attach_property_key_pressed (GtkWidget *widget,
267 gboolean *cancelled);
269 static void compose_exec_ext_editor (Compose *compose);
270 static gint compose_exec_ext_editor_real (const gchar *file);
271 static gboolean compose_ext_editor_kill (Compose *compose);
272 static void compose_input_cb (gpointer data,
274 GdkInputCondition condition);
275 static void compose_set_ext_editor_sensitive (Compose *compose,
278 static void compose_undo_state_changed (UndoMain *undostruct,
283 static gint calc_cursor_xpos (GtkSText *text,
287 static void compose_create_header_entry (Compose *compose);
288 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
289 static void compose_update_priority_menu_item(Compose * compose);
291 /* callback functions */
293 static gboolean compose_edit_size_alloc (GtkEditable *widget,
294 GtkAllocation *allocation,
295 GtkSHRuler *shruler);
297 static void toolbar_send_cb (GtkWidget *widget,
299 static void toolbar_send_later_cb (GtkWidget *widget,
301 static void toolbar_draft_cb (GtkWidget *widget,
303 static void toolbar_insert_cb (GtkWidget *widget,
305 static void toolbar_attach_cb (GtkWidget *widget,
307 static void toolbar_sig_cb (GtkWidget *widget,
309 static void toolbar_ext_editor_cb (GtkWidget *widget,
311 static void toolbar_linewrap_cb (GtkWidget *widget,
313 static void toolbar_address_cb (GtkWidget *widget,
315 static void toolbar_actions_execute_cb (GtkWidget *widget,
317 static void toolbar_compose_buttons_cb (GtkWidget *widget,
319 ToolbarItem *t_item);
320 static void account_activated (GtkMenuItem *menuitem,
323 static void attach_selected (GtkCList *clist,
328 static void attach_button_pressed (GtkWidget *widget,
329 GdkEventButton *event,
331 static void attach_key_pressed (GtkWidget *widget,
335 static void compose_send_cb (gpointer data,
338 static void compose_send_later_cb (gpointer data,
342 static void compose_draft_cb (gpointer data,
346 static void compose_attach_cb (gpointer data,
349 static void compose_insert_file_cb (gpointer data,
353 static void compose_close_cb (gpointer data,
357 static void compose_address_cb (gpointer data,
360 static void compose_template_activate_cb(GtkWidget *widget,
363 static void compose_ext_editor_cb (gpointer data,
367 static gint compose_delete_cb (GtkWidget *widget,
370 static void compose_destroy_cb (GtkWidget *widget,
373 static void compose_undo_cb (Compose *compose);
374 static void compose_redo_cb (Compose *compose);
375 static void compose_cut_cb (Compose *compose);
376 static void compose_copy_cb (Compose *compose);
377 static void compose_paste_cb (Compose *compose);
378 static void compose_paste_as_quote_cb (Compose *compose);
379 static void compose_allsel_cb (Compose *compose);
381 static void compose_gtk_stext_action_cb (Compose *compose,
382 ComposeCallGtkSTextAction action);
384 static void compose_grab_focus_cb (GtkWidget *widget,
387 static void compose_changed_cb (GtkEditable *editable,
389 static void compose_button_press_cb (GtkWidget *widget,
390 GdkEventButton *event,
393 static void compose_key_press_cb (GtkWidget *widget,
399 static void compose_toggle_to_cb (gpointer data,
402 static void compose_toggle_cc_cb (gpointer data,
405 static void compose_toggle_bcc_cb (gpointer data,
408 static void compose_toggle_replyto_cb (gpointer data,
411 static void compose_toggle_followupto_cb(gpointer data,
414 static void compose_toggle_attach_cb (gpointer data,
418 static void compose_toggle_ruler_cb (gpointer data,
422 static void compose_toggle_sign_cb (gpointer data,
425 static void compose_toggle_encrypt_cb (gpointer data,
429 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
431 static void compose_set_priority_cb (gpointer data,
435 static void compose_attach_drag_received_cb (GtkWidget *widget,
436 GdkDragContext *drag_context,
439 GtkSelectionData *data,
443 static void compose_insert_drag_received_cb (GtkWidget *widget,
444 GdkDragContext *drag_context,
447 GtkSelectionData *data,
453 static void to_activated (GtkWidget *widget,
455 static void newsgroups_activated (GtkWidget *widget,
457 static void cc_activated (GtkWidget *widget,
459 static void bcc_activated (GtkWidget *widget,
461 static void replyto_activated (GtkWidget *widget,
463 static void followupto_activated (GtkWidget *widget,
465 static void subject_activated (GtkWidget *widget,
469 static void text_activated (GtkWidget *widget,
471 static void text_inserted (GtkWidget *widget,
476 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
478 gboolean ignore_replyto,
479 gboolean followup_and_reply_to,
482 void compose_headerentry_changed_cb (GtkWidget *entry,
483 ComposeHeaderEntry *headerentry);
484 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
486 ComposeHeaderEntry *headerentry);
488 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
491 static void compose_check_all (Compose *compose);
492 static void compose_highlight_all (Compose *compose);
493 static void compose_check_backwards (Compose *compose);
494 static void compose_check_forwards_go (Compose *compose);
497 static gboolean compose_send_control_enter (Compose *compose);
499 static GtkItemFactoryEntry compose_popup_entries[] =
501 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
502 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
503 {N_("/---"), NULL, NULL, 0, "<Separator>"},
504 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
507 static GtkItemFactoryEntry compose_entries[] =
509 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
510 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
511 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
512 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
513 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
514 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
516 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
517 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
518 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
519 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
520 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
521 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
522 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
523 {N_("/_Edit/Paste as _quotation"),
524 NULL, compose_paste_as_quote_cb, 0, NULL},
525 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
526 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
527 {N_("/_Edit/A_dvanced/Move a character backward"),
529 compose_gtk_stext_action_cb,
530 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
532 {N_("/_Edit/A_dvanced/Move a character forward"),
534 compose_gtk_stext_action_cb,
535 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
537 {N_("/_Edit/A_dvanced/Move a word backward"),
539 compose_gtk_stext_action_cb,
540 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
542 {N_("/_Edit/A_dvanced/Move a word forward"),
544 compose_gtk_stext_action_cb,
545 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
547 {N_("/_Edit/A_dvanced/Move to beginning of line"),
548 NULL, /* "<control>A" */
549 compose_gtk_stext_action_cb,
550 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
552 {N_("/_Edit/A_dvanced/Move to end of line"),
554 compose_gtk_stext_action_cb,
555 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
557 {N_("/_Edit/A_dvanced/Move to previous line"),
559 compose_gtk_stext_action_cb,
560 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
562 {N_("/_Edit/A_dvanced/Move to next line"),
564 compose_gtk_stext_action_cb,
565 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
567 {N_("/_Edit/A_dvanced/Delete a character backward"),
569 compose_gtk_stext_action_cb,
570 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
572 {N_("/_Edit/A_dvanced/Delete a character forward"),
574 compose_gtk_stext_action_cb,
575 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
577 {N_("/_Edit/A_dvanced/Delete a word backward"),
578 NULL, /* "<control>W" */
579 compose_gtk_stext_action_cb,
580 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
582 {N_("/_Edit/A_dvanced/Delete a word forward"),
583 NULL, /* "<alt>D", */
584 compose_gtk_stext_action_cb,
585 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
587 {N_("/_Edit/A_dvanced/Delete line"),
589 compose_gtk_stext_action_cb,
590 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
592 {N_("/_Edit/A_dvanced/Delete entire line"),
594 compose_gtk_stext_action_cb,
595 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
597 {N_("/_Edit/A_dvanced/Delete to end of line"),
599 compose_gtk_stext_action_cb,
600 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
602 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
603 {N_("/_Edit/_Wrap current paragraph"),
604 "<control>L", compose_wrap_line, 0, NULL},
605 {N_("/_Edit/Wrap all long _lines"),
606 "<control><alt>L", compose_wrap_line_all, 0, NULL},
607 {N_("/_Edit/Edit with e_xternal editor"),
608 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
610 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
611 {N_("/_Spelling/_Check all or check selection"),
612 NULL, compose_check_all, 0, NULL},
613 {N_("/_Spelling/_Highlight all misspelled words"),
614 NULL, compose_highlight_all, 0, NULL},
615 {N_("/_Spelling/Check _backwards misspelled word"),
616 NULL, compose_check_backwards , 0, NULL},
617 {N_("/_Spelling/_Forward to next misspelled word"),
618 NULL, compose_check_forwards_go, 0, NULL},
619 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
620 {N_("/_Spelling/_Spelling Configuration"),
621 NULL, NULL, 0, "<Branch>"},
623 #if 0 /* NEW COMPOSE GUI */
624 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
625 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
626 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
627 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
628 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
629 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
630 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
631 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
632 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
633 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
634 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
636 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
637 {N_("/_Message/_Send"), "<control>Return",
638 compose_send_cb, 0, NULL},
639 {N_("/_Message/Send _later"), "<shift><control>S",
640 compose_send_later_cb, 0, NULL},
641 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
642 {N_("/_Message/Save to _draft folder"),
643 "<shift><control>D", compose_draft_cb, 0, NULL},
644 {N_("/_Message/Save and _keep editing"),
645 "<control>S", compose_draft_cb, 1, NULL},
646 #if 0 /* NEW COMPOSE GUI */
647 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
648 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
649 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
650 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
651 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
652 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
653 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
654 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
655 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
658 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
659 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
660 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
661 #endif /* USE_GPGME */
662 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
663 {N_("/_Message/_Priority"), NULL, NULL, 0, "<Branch>"},
664 {N_("/_Message/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
665 {N_("/_Message/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
666 {N_("/_Message/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
667 {N_("/_Message/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
668 {N_("/_Message/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
669 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
670 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
671 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
672 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
673 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
674 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
675 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
676 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
677 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
680 static GtkTargetEntry compose_mime_types[] =
682 {"text/uri-list", 0, 0}
685 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
686 GPtrArray *attach_files)
688 return compose_generic_new(account, mailto, NULL, attach_files);
691 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
693 return compose_generic_new(account, NULL, item, NULL);
696 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
697 GPtrArray *attach_files)
701 GtkItemFactory *ifactory;
702 gboolean grab_focus_on_last = TRUE;
704 if (item && item->prefs && item->prefs->enable_default_account)
705 account = account_find_from_id(item->prefs->default_account);
707 if (!account) account = cur_account;
708 g_return_val_if_fail(account != NULL, NULL);
710 compose = compose_create(account, COMPOSE_NEW);
711 ifactory = gtk_item_factory_from_widget(compose->menubar);
713 compose->replyinfo = NULL;
715 text = GTK_STEXT(compose->text);
716 gtk_stext_freeze(text);
718 if (prefs_common.auto_sig)
719 compose_insert_sig(compose);
720 gtk_editable_set_position(GTK_EDITABLE(text), 0);
721 gtk_stext_set_point(text, 0);
723 gtk_stext_thaw(text);
725 /* workaround for initial XIM problem */
726 gtk_widget_grab_focus(compose->text);
727 gtkut_widget_wait_for_draw(compose->text);
729 if (account->protocol != A_NNTP) {
730 if (mailto && *mailto != '\0') {
731 compose_entries_set(compose, mailto);
733 } else if (item && item->prefs->enable_default_to) {
734 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
735 compose_entry_select(compose, item->prefs->default_to);
736 grab_focus_on_last = FALSE;
738 if (item && item->ret_rcpt) {
739 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
743 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
746 * CLAWS: just don't allow return receipt request, even if the user
747 * may want to send an email. simple but foolproof.
749 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
756 for (i = 0; i < attach_files->len; i++) {
757 file = g_ptr_array_index(attach_files, i);
758 compose_attach_append(compose, file, file, NULL);
762 compose_show_first_last_header(compose, TRUE);
764 /* Set save folder */
765 if (item && item->prefs && item->prefs->save_copy_to_folder) {
766 gchar *folderidentifier;
768 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
769 folderidentifier = folder_item_get_identifier(item);
770 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
771 g_free(folderidentifier);
774 /* Grab focus on last header only if no default_to was set */
775 if (grab_focus_on_last)
776 gtk_widget_grab_focus(compose->header_last->entry);
778 if (prefs_common.auto_exteditor)
779 compose_exec_ext_editor(compose);
784 #define CHANGE_FLAGS(msginfo) \
786 if (msginfo->folder->folder->change_flags != NULL) \
787 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
793 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
794 const gchar *followupto, gchar * to)
798 if (!account) account = cur_account;
799 g_return_val_if_fail(account != NULL, NULL);
800 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
802 compose = compose_create(account, COMPOSE_NEW);
804 if (prefs_common.auto_sig)
805 compose_insert_sig(compose);
806 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
807 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
809 compose_entry_append(compose, to, COMPOSE_TO);
810 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
811 gtk_widget_grab_focus(compose->subject_entry);
817 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
818 gboolean ignore_replyto, const gchar *body)
820 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, FALSE,
824 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
826 gboolean ignore_replyto,
829 compose_generic_reply(msginfo, quote, to_all, ignore_replyto, TRUE,
833 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
835 gboolean ignore_replyto,
836 gboolean followup_and_reply_to,
840 PrefsAccount *account;
841 PrefsAccount *reply_account;
844 g_return_if_fail(msginfo != NULL);
845 g_return_if_fail(msginfo->folder != NULL);
848 /* select the account set in folderitem's property (if enabled) */
849 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
850 account = account_find_from_id(msginfo->folder->prefs->default_account);
852 /* select the account for the whole folder (IMAP / NNTP) */
854 /* FIXME: this is not right, because folder may be nested. we should
855 * ascend the tree until we find a parent with proper account
857 account = msginfo->folder->folder->account;
859 /* select account by to: and cc: header if enabled */
860 if (prefs_common.reply_account_autosel) {
861 if (!account && msginfo->to) {
863 Xstrdup_a(to, msginfo->to, return);
865 account = account_find_from_address(to);
869 if (!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
871 account = account_find_from_address(cc);
876 /* select current account */
877 if (!account) account = cur_account;
878 g_return_if_fail(account != NULL);
880 if (ignore_replyto && account->protocol == A_NNTP &&
881 !followup_and_reply_to) {
883 account_find_from_address(account->address);
885 reply_account = compose_current_mail_account();
889 reply_account = account;
891 compose = compose_create(account, COMPOSE_REPLY);
892 compose->replyinfo = procmsg_msginfo_new_ref(msginfo);
894 #if 0 /* NEW COMPOSE GUI */
895 if (followup_and_reply_to) {
896 gtk_widget_show(compose->to_hbox);
897 gtk_widget_show(compose->to_entry);
898 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
899 compose->use_to = TRUE;
902 if (msginfo->folder && msginfo->folder->ret_rcpt) {
903 GtkItemFactory *ifactory;
905 ifactory = gtk_item_factory_from_widget(compose->menubar);
906 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
909 /* Set save folder */
910 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
911 gchar *folderidentifier;
913 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
914 folderidentifier = folder_item_get_identifier(msginfo->folder);
915 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
916 g_free(folderidentifier);
919 if (compose_parse_header(compose, msginfo) < 0) return;
920 compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
921 followup_and_reply_to);
922 compose_show_first_last_header(compose, TRUE);
924 text = GTK_STEXT(compose->text);
925 gtk_stext_freeze(text);
931 if (prefs_common.quotemark && *prefs_common.quotemark)
932 qmark = prefs_common.quotemark;
936 quote_str = compose_quote_fmt(compose, msginfo,
937 prefs_common.quotefmt,
941 if (prefs_common.auto_sig)
942 compose_insert_sig(compose);
944 if (quote && prefs_common.linewrap_quote)
945 compose_wrap_line_all(compose);
947 gtk_editable_set_position(GTK_EDITABLE(text), 0);
948 gtk_stext_set_point(text, 0);
950 gtk_stext_thaw(text);
951 gtk_widget_grab_focus(compose->text);
953 if (prefs_common.auto_exteditor)
954 compose_exec_ext_editor(compose);
957 static void set_toolbar_style(Compose *compose);
959 #define INSERT_FW_HEADER(var, hdr) \
960 if (msginfo->var && *msginfo->var) { \
961 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
962 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
963 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
966 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
967 gboolean as_attach, const gchar *body)
970 /* PrefsAccount *account; */
973 g_return_val_if_fail(msginfo != NULL, NULL);
974 g_return_val_if_fail(msginfo->folder != NULL, NULL);
976 account = msginfo->folder->folder->account;
977 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
979 Xstrdup_a(to, msginfo->to, return NULL);
981 account = account_find_from_address(to);
984 if (!account && prefs_common.forward_account_autosel) {
986 if (!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
988 account = account_find_from_address(cc);
992 if (account == NULL) {
993 account = cur_account;
995 account = msginfo->folder->folder->account;
996 if (!account) account = cur_account;
999 g_return_val_if_fail(account != NULL, NULL);
1001 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1002 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1003 if (MSG_IS_IMAP(msginfo->flags))
1004 imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
1005 CHANGE_FLAGS(msginfo);
1007 compose = compose_create(account, COMPOSE_FORWARD);
1009 if (msginfo->subject && *msginfo->subject) {
1010 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1011 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1015 text = GTK_STEXT(compose->text);
1016 gtk_stext_freeze(text);
1022 msgfile = procmsg_get_message_file_path(msginfo);
1023 if (!is_file_exist(msgfile))
1024 g_warning(_("%s: file not exist\n"), msgfile);
1026 compose_attach_append(compose, msgfile, msgfile,
1034 if (prefs_common.fw_quotemark &&
1035 *prefs_common.fw_quotemark)
1036 qmark = prefs_common.fw_quotemark;
1040 quote_str = compose_quote_fmt(compose, msginfo,
1041 prefs_common.fw_quotefmt,
1043 compose_attach_parts(compose, msginfo);
1046 if (prefs_common.auto_sig)
1047 compose_insert_sig(compose);
1049 if (prefs_common.linewrap_quote)
1050 compose_wrap_line_all(compose);
1052 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1053 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1055 gtk_stext_thaw(text);
1056 #if 0 /* NEW COMPOSE GUI */
1057 if (account->protocol != A_NNTP)
1058 gtk_widget_grab_focus(compose->to_entry);
1060 gtk_widget_grab_focus(compose->newsgroups_entry);
1062 gtk_widget_grab_focus(compose->header_last->entry);
1064 if (prefs_common.auto_exteditor)
1065 compose_exec_ext_editor(compose);
1070 #undef INSERT_FW_HEADER
1072 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1079 g_return_val_if_fail(msginfo_list != NULL, NULL);
1081 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1082 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1086 if (account == NULL) {
1087 account = cur_account;
1089 account = msginfo->folder->folder->account;
1090 if (!account) account = cur_account;
1093 g_return_val_if_fail(account != NULL, NULL);
1095 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1096 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1097 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1098 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1101 compose = compose_create(account, COMPOSE_FORWARD);
1103 text = GTK_STEXT(compose->text);
1104 gtk_stext_freeze(text);
1106 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1107 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1108 if (!is_file_exist(msgfile))
1109 g_warning(_("%s: file not exist\n"), msgfile);
1111 compose_attach_append(compose, msgfile, msgfile,
1116 if (prefs_common.auto_sig)
1117 compose_insert_sig(compose);
1119 if (prefs_common.linewrap_quote)
1120 compose_wrap_line_all(compose);
1122 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1123 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1125 gtk_stext_thaw(text);
1126 gtk_widget_grab_focus(compose->header_last->entry);
1128 #if 0 /* NEW COMPOSE GUI */
1129 if (account->protocol != A_NNTP)
1130 gtk_widget_grab_focus(compose->to_entry);
1132 gtk_widget_grab_focus(compose->newsgroups_entry);
1138 void compose_reedit(MsgInfo *msginfo)
1141 PrefsAccount *account = NULL;
1144 gchar buf[BUFFSIZE];
1146 g_return_if_fail(msginfo != NULL);
1147 g_return_if_fail(msginfo->folder != NULL);
1149 if (msginfo->folder->stype == F_QUEUE) {
1150 gchar queueheader_buf[BUFFSIZE];
1153 /* Select Account from queue headers */
1154 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1155 sizeof(queueheader_buf), "NAID:")) {
1156 id = atoi(&queueheader_buf[5]);
1157 account = account_find_from_id(id);
1159 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1160 sizeof(queueheader_buf), "MAID:")) {
1161 id = atoi(&queueheader_buf[5]);
1162 account = account_find_from_id(id);
1164 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1165 sizeof(queueheader_buf), "S:")) {
1166 account = account_find_from_address(queueheader_buf);
1169 account = msginfo->folder->folder->account;
1171 if (!account && prefs_common.reedit_account_autosel) {
1172 gchar from[BUFFSIZE];
1173 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1174 extract_address(from);
1175 account = account_find_from_address(from);
1178 if (!account) account = cur_account;
1179 g_return_if_fail(account != NULL);
1181 compose = compose_create(account, COMPOSE_REEDIT);
1182 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1184 if (msginfo->folder->stype == F_QUEUE
1185 || msginfo->folder->stype == F_DRAFT) {
1186 gchar queueheader_buf[BUFFSIZE];
1188 /* Set message save folder */
1189 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1192 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1193 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1194 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1198 if (compose_parse_header(compose, msginfo) < 0) return;
1199 compose_reedit_set_entry(compose, msginfo);
1201 text = GTK_STEXT(compose->text);
1202 gtk_stext_freeze(text);
1204 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1205 g_warning(_("Can't get text part\n"));
1207 while (fgets(buf, sizeof(buf), fp) != NULL)
1208 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1211 compose_attach_parts(compose, msginfo);
1213 gtk_stext_thaw(text);
1214 gtk_widget_grab_focus(compose->text);
1216 if (prefs_common.auto_exteditor)
1217 compose_exec_ext_editor(compose);
1220 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1224 GtkItemFactory *ifactory;
1226 g_return_val_if_fail(msginfo != NULL, NULL);
1229 account = cur_account;
1230 g_return_val_if_fail(account != NULL, NULL);
1232 compose = compose_create(account, COMPOSE_REDIRECT);
1233 ifactory = gtk_item_factory_from_widget(compose->menubar);
1235 compose->replyinfo = NULL;
1237 compose_show_first_last_header(compose, TRUE);
1239 gtk_widget_grab_focus(compose->header_last->entry);
1241 filename = procmsg_get_message_file(msginfo);
1242 if (filename == NULL)
1245 compose->redirect_filename = filename;
1247 if (msginfo->subject)
1248 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1250 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1252 gtk_stext_freeze(GTK_STEXT(compose->text));
1253 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1254 gtk_editable_set_editable(GTK_EDITABLE(compose->text), FALSE);
1255 gtk_stext_thaw(GTK_STEXT(compose->text));
1257 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1258 menu_set_sensitive(ifactory, "/Add...", FALSE);
1259 menu_set_sensitive(ifactory, "/Remove", FALSE);
1260 menu_set_sensitive(ifactory, "/Property...", FALSE);
1262 ifactory = gtk_item_factory_from_widget(compose->menubar);
1263 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
1264 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
1265 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
1266 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
1267 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
1268 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
1269 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
1270 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
1272 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
1273 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
1275 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
1276 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
1278 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1279 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1280 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1281 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1282 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, FALSE);
1287 GList *compose_get_compose_list(void)
1289 return compose_list;
1292 void compose_entry_append(Compose *compose, const gchar *address,
1293 ComposeEntryType type)
1297 if (!address || *address == '\0') return;
1299 #if 0 /* NEW COMPOSE GUI */
1302 entry = GTK_ENTRY(compose->cc_entry);
1305 entry = GTK_ENTRY(compose->bcc_entry);
1307 case COMPOSE_NEWSGROUPS:
1308 entry = GTK_ENTRY(compose->newsgroups_entry);
1312 entry = GTK_ENTRY(compose->to_entry);
1316 text = gtk_entry_get_text(entry);
1318 gtk_entry_append_text(entry, ", ");
1319 gtk_entry_append_text(entry, address);
1327 header = N_("Bcc:");
1329 case COMPOSE_REPLYTO:
1330 header = N_("Reply-To:");
1332 case COMPOSE_NEWSGROUPS:
1333 header = N_("Newsgroups:");
1335 case COMPOSE_FOLLOWUPTO:
1336 header = N_( "Followup-To:");
1343 header = prefs_common.trans_hdr ? gettext(header) : header;
1345 compose_add_header_entry(compose, header, (gchar *)address);
1348 void compose_entry_select (Compose *compose, const gchar *mailto)
1350 GSList *header_list;
1352 for (header_list = compose->header_list; header_list != NULL; header_list = header_list->next) {
1353 GtkEntry * entry = GTK_ENTRY(((ComposeHeaderEntry *)header_list->data)->entry);
1355 if (gtk_entry_get_text(entry) && !g_strcasecmp(gtk_entry_get_text(entry), mailto)) {
1356 gtk_entry_select_region(entry, 0, -1);
1357 gtk_widget_grab_focus(GTK_WIDGET(entry));
1362 static void compose_entries_set(Compose *compose, const gchar *mailto)
1364 gchar *subject = NULL;
1372 Xstrdup_a(tmp_mailto, mailto, return);
1376 p = strchr(tmp_mailto, '?');
1383 gchar *field, *value;
1400 if (*value == '\0') continue;
1402 if (!g_strcasecmp(field, "subject")) {
1403 Xalloca(subject, strlen(value) + 1, return);
1404 decode_uri(subject, value);
1405 } else if (!g_strcasecmp(field, "cc")) {
1407 } else if (!g_strcasecmp(field, "bcc")) {
1409 } else if (!g_strcasecmp(field, "body")) {
1410 Xalloca(body, strlen(value) + 1, return);
1411 decode_uri(body, value);
1416 compose_entry_append(compose, to, COMPOSE_TO);
1418 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1420 compose_entry_append(compose, cc, COMPOSE_CC);
1422 compose_entry_append(compose, bcc, COMPOSE_BCC);
1424 gtk_stext_insert(GTK_STEXT(compose->text),
1425 NULL, NULL, NULL, body, -1);
1426 gtk_stext_insert(GTK_STEXT(compose->text),
1427 NULL, NULL, NULL, "\n", 1);
1431 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1433 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1434 {"Cc:", NULL, FALSE},
1435 {"References:", NULL, FALSE},
1436 {"Bcc:", NULL, FALSE},
1437 {"Newsgroups:", NULL, FALSE},
1438 {"Followup-To:", NULL, FALSE},
1439 {"X-Mailing-List:", NULL, FALSE},
1440 {"X-BeenThere:", NULL, FALSE},
1441 {"X-Priority:", NULL, FALSE},
1442 {NULL, NULL, FALSE}};
1452 H_X_MAILING_LIST = 6,
1459 g_return_val_if_fail(msginfo != NULL, -1);
1461 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1462 procheader_get_header_fields(fp, hentry);
1465 if (hentry[H_REPLY_TO].body != NULL) {
1466 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1467 compose->replyto = hentry[H_REPLY_TO].body;
1468 hentry[H_REPLY_TO].body = NULL;
1470 if (hentry[H_CC].body != NULL) {
1471 conv_unmime_header_overwrite(hentry[H_CC].body);
1472 compose->cc = hentry[H_CC].body;
1473 hentry[H_CC].body = NULL;
1475 if (hentry[H_X_MAILING_LIST].body != NULL) {
1476 /* this is good enough to parse debian-devel */
1477 gchar *buf = g_malloc(strlen(hentry[H_X_MAILING_LIST].body) + 1);
1478 g_return_val_if_fail(buf != NULL, -1 );
1479 if (1 == sscanf(hentry[H_X_MAILING_LIST].body, "<%[^>]>", buf))
1480 compose->mailinglist = g_strdup(buf);
1482 g_free(hentry[H_X_MAILING_LIST].body);
1483 hentry[H_X_MAILING_LIST].body = NULL ;
1485 if (hentry[H_X_BEENTHERE].body != NULL) {
1486 /* this is good enough to parse the sylpheed-claws lists */
1487 gchar *buf = g_malloc(strlen(hentry[H_X_BEENTHERE].body) + 1);
1488 g_return_val_if_fail(buf != NULL, -1 );
1489 if (1 == sscanf(hentry[H_X_BEENTHERE].body, "%[^>]", buf))
1490 compose->mailinglist = g_strdup(buf);
1492 g_free(hentry[H_X_BEENTHERE].body);
1493 hentry[H_X_BEENTHERE].body = NULL ;
1495 if (hentry[H_REFERENCES].body != NULL) {
1496 if (compose->mode == COMPOSE_REEDIT)
1497 compose->references = hentry[H_REFERENCES].body;
1499 compose->references = compose_parse_references
1500 (hentry[H_REFERENCES].body, msginfo->msgid);
1501 g_free(hentry[H_REFERENCES].body);
1503 hentry[H_REFERENCES].body = NULL;
1505 if (hentry[H_BCC].body != NULL) {
1506 if (compose->mode == COMPOSE_REEDIT) {
1507 conv_unmime_header_overwrite(hentry[H_BCC].body);
1508 compose->bcc = hentry[H_BCC].body;
1510 g_free(hentry[H_BCC].body);
1511 hentry[H_BCC].body = NULL;
1513 if (hentry[H_NEWSGROUPS].body != NULL) {
1514 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1515 hentry[H_NEWSGROUPS].body = NULL;
1517 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1518 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1519 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1520 hentry[H_FOLLOWUP_TO].body = NULL;
1523 if (compose->mode == COMPOSE_REEDIT)
1524 if (hentry[H_X_PRIORITY].body != NULL) {
1527 priority = atoi(hentry[H_X_PRIORITY].body);
1528 g_free(hentry[H_X_PRIORITY].body);
1530 hentry[H_X_PRIORITY].body = NULL;
1532 if (priority < PRIORITY_HIGHEST ||
1533 priority > PRIORITY_LOWEST)
1534 priority = PRIORITY_NORMAL;
1536 compose->priority = priority;
1539 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1540 compose->inreplyto = g_strdup(msginfo->inreplyto);
1541 else if (compose->mode != COMPOSE_REEDIT &&
1542 msginfo->msgid && *msginfo->msgid) {
1543 compose->inreplyto = g_strdup(msginfo->msgid);
1545 if (!compose->references) {
1546 if (msginfo->inreplyto && *msginfo->inreplyto)
1547 compose->references =
1548 g_strdup_printf("<%s>\n\t<%s>",
1552 compose->references =
1553 g_strconcat("<", msginfo->msgid, ">",
1561 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1563 GSList *ref_id_list, *cur;
1567 ref_id_list = references_list_append(NULL, ref);
1568 if (!ref_id_list) return NULL;
1569 if (msgid && *msgid)
1570 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1575 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1576 /* "<" + Message-ID + ">" + CR+LF+TAB */
1577 len += strlen((gchar *)cur->data) + 5;
1579 if (len > MAX_REFERENCES_LEN) {
1580 /* remove second message-ID */
1581 if (ref_id_list && ref_id_list->next &&
1582 ref_id_list->next->next) {
1583 g_free(ref_id_list->next->data);
1584 ref_id_list = g_slist_remove
1585 (ref_id_list, ref_id_list->next->data);
1587 slist_free_strings(ref_id_list);
1588 g_slist_free(ref_id_list);
1595 new_ref = g_string_new("");
1596 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1597 if (new_ref->len > 0)
1598 g_string_append(new_ref, "\n\t");
1599 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1602 slist_free_strings(ref_id_list);
1603 g_slist_free(ref_id_list);
1605 new_ref_str = new_ref->str;
1606 g_string_free(new_ref, FALSE);
1611 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1612 const gchar *fmt, const gchar *qmark,
1615 GtkSText *text = GTK_STEXT(compose->text);
1616 static MsgInfo dummyinfo;
1617 gchar *quote_str = NULL;
1623 msginfo = &dummyinfo;
1625 if (qmark != NULL) {
1626 quote_fmt_init(msginfo, NULL, NULL);
1627 quote_fmt_scan_string(qmark);
1630 buf = quote_fmt_get_buffer();
1632 alertpanel_error(_("Quote mark format error."));
1634 Xstrdup_a(quote_str, buf, return NULL)
1637 if (fmt && *fmt != '\0') {
1638 quote_fmt_init(msginfo, quote_str, body);
1639 quote_fmt_scan_string(fmt);
1642 buf = quote_fmt_get_buffer();
1644 alertpanel_error(_("Message reply/forward format error."));
1650 gtk_stext_freeze(text);
1652 for (p = buf; *p != '\0'; ) {
1653 lastp = strchr(p, '\n');
1654 len = lastp ? lastp - p + 1 : -1;
1655 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1662 gtk_stext_thaw(text);
1667 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1668 gboolean to_all, gboolean ignore_replyto,
1669 gboolean followup_and_reply_to)
1671 GSList *cc_list = NULL;
1674 gchar *replyto = NULL;
1675 GHashTable *to_table;
1677 g_return_if_fail(compose->account != NULL);
1678 g_return_if_fail(msginfo != NULL);
1680 if ((compose->account->protocol != A_NNTP) || followup_and_reply_to)
1681 compose_entry_append(compose,
1682 ((compose->replyto && !ignore_replyto)
1684 : (compose->mailinglist && !ignore_replyto)
1685 ? compose->mailinglist
1686 : msginfo->from ? msginfo->from : ""),
1689 if (compose->account->protocol == A_NNTP) {
1691 compose_entry_append
1692 (compose, msginfo->from ? msginfo->from : "",
1695 if (compose->followup_to && !strncmp(compose->followup_to,"poster",6)) {
1696 compose_entry_append
1698 ((compose->replyto && !ignore_replyto)
1700 : (compose->mailinglist && !ignore_replyto)
1701 ? compose->mailinglist
1702 : msginfo->from ? msginfo->from : ""),
1705 compose_entry_append
1707 compose->followup_to ? compose->followup_to
1708 : compose->newsgroups ? compose->newsgroups
1710 COMPOSE_NEWSGROUPS);
1715 if (msginfo->subject && *msginfo->subject) {
1716 gchar *buf, *buf2, *p;
1718 buf = g_strdup(msginfo->subject);
1719 while (!strncasecmp(buf, "Re:", 3)) {
1721 while (isspace(*p)) p++;
1722 memmove(buf, p, strlen(p) + 1);
1725 buf2 = g_strdup_printf("Re: %s", buf);
1726 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1730 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1732 if (!to_all || compose->account->protocol == A_NNTP) return;
1734 if (compose->replyto) {
1735 Xstrdup_a(replyto, compose->replyto, return);
1736 extract_address(replyto);
1738 if (msginfo->from) {
1739 Xstrdup_a(from, msginfo->from, return);
1740 extract_address(from);
1743 if (compose->mailinglist && from) {
1744 cc_list = address_list_append(cc_list, from);
1747 if (replyto && from)
1748 cc_list = address_list_append(cc_list, from);
1750 if (!compose->mailinglist)
1751 cc_list = address_list_append(cc_list, msginfo->to);
1753 cc_list = address_list_append(cc_list, compose->cc);
1755 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1757 g_hash_table_insert(to_table, replyto, GINT_TO_POINTER(1));
1758 if (compose->account)
1759 g_hash_table_insert(to_table, compose->account->address,
1760 GINT_TO_POINTER(1));
1762 /* remove address on To: and that of current account */
1763 for (cur = cc_list; cur != NULL; ) {
1764 GSList *next = cur->next;
1766 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1767 cc_list = g_slist_remove(cc_list, cur->data);
1769 g_hash_table_insert(to_table, cur->data, cur);
1773 g_hash_table_destroy(to_table);
1776 for (cur = cc_list; cur != NULL; cur = cur->next)
1777 compose_entry_append(compose, (gchar *)cur->data,
1779 slist_free_strings(cc_list);
1780 g_slist_free(cc_list);
1784 #define SET_ENTRY(entry, str) \
1787 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1790 #define SET_ADDRESS(type, str) \
1793 compose_entry_append(compose, str, type); \
1796 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1798 g_return_if_fail(msginfo != NULL);
1800 SET_ENTRY(subject_entry, msginfo->subject);
1801 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1802 SET_ADDRESS(COMPOSE_CC, compose->cc);
1803 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1804 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1806 compose_update_priority_menu_item(compose);
1808 compose_show_first_last_header(compose, TRUE);
1810 #if 0 /* NEW COMPOSE GUI */
1812 GtkItemFactory *ifactory;
1813 GtkWidget *menuitem;
1815 ifactory = gtk_item_factory_from_widget(compose->menubar);
1816 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
1817 gtk_check_menu_item_set_active
1818 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1820 if (compose->replyto) {
1821 GtkItemFactory *ifactory;
1822 GtkWidget *menuitem;
1824 ifactory = gtk_item_factory_from_widget(compose->menubar);
1825 menuitem = gtk_item_factory_get_item
1826 (ifactory, "/View/Reply to");
1827 gtk_check_menu_item_set_active
1828 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1836 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1840 size_t buf_len = 128;
1842 if (strlen(sigfile) < 2)
1845 sigprg = popen(sigfile+1, "r");
1848 buf = g_malloc(buf_len);
1851 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1852 "Unable to insert signature (malloc failed)\n", -1);
1858 while (!feof(sigprg)) {
1859 bzero(buf, buf_len);
1860 fread(buf, buf_len-1, 1, sigprg);
1861 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1869 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1870 "Can't exec file: ", -1);
1871 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1876 static void compose_insert_sig(Compose *compose)
1880 if (compose->account && compose->account->sig_path)
1881 sigfile = g_strdup(compose->account->sig_path);
1883 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1884 DEFAULT_SIGNATURE, NULL);
1886 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1891 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1892 if (prefs_common.sig_sep) {
1893 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1894 prefs_common.sig_sep, -1);
1895 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1899 if (sigfile[0] == '|')
1900 compose_exec_sig(compose, sigfile);
1902 compose_insert_file(compose, sigfile);
1906 static void compose_insert_file(Compose *compose, const gchar *file)
1908 GtkSText *text = GTK_STEXT(compose->text);
1909 gchar buf[BUFFSIZE];
1913 g_return_if_fail(file != NULL);
1915 if ((fp = fopen(file, "rb")) == NULL) {
1916 FILE_OP_ERROR(file, "fopen");
1920 gtk_stext_freeze(text);
1922 while (fgets(buf, sizeof(buf), fp) != NULL) {
1923 /* strip <CR> if DOS/Windows file,
1924 replace <CR> with <LF> if Macintosh file. */
1927 if (len > 0 && buf[len - 1] != '\n') {
1929 if (buf[len] == '\r') buf[len] = '\n';
1931 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1934 gtk_stext_thaw(text);
1939 static void compose_attach_append(Compose *compose, const gchar *file,
1940 const gchar *filename,
1941 const gchar *content_type)
1944 gchar *text[N_ATTACH_COLS];
1949 if (!is_file_exist(file)) {
1950 g_warning(_("File %s doesn't exist\n"), file);
1953 if ((size = get_file_size(file)) < 0) {
1954 g_warning(_("Can't get file size of %s\n"), file);
1958 alertpanel_notice(_("File %s is empty."), file);
1961 if ((fp = fopen(file, "rb")) == NULL) {
1962 alertpanel_error(_("Can't read %s."), file);
1967 #if 0 /* NEW COMPOSE GUI */
1968 if (!compose->use_attach) {
1969 GtkItemFactory *ifactory;
1970 GtkWidget *menuitem;
1972 ifactory = gtk_item_factory_from_widget(compose->menubar);
1973 menuitem = gtk_item_factory_get_item(ifactory,
1974 "/View/Attachment");
1975 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1979 ainfo = g_new0(AttachInfo, 1);
1980 ainfo->file = g_strdup(file);
1983 ainfo->content_type = g_strdup(content_type);
1984 if (!strcasecmp(content_type, "message/rfc822")) {
1985 ainfo->encoding = ENC_7BIT;
1986 ainfo->name = g_strdup_printf
1988 g_basename(filename ? filename : file));
1990 if (!g_strncasecmp(content_type, "text", 4))
1992 procmime_get_encoding_for_file(file);
1994 ainfo->encoding = ENC_BASE64;
1995 ainfo->name = g_strdup
1996 (g_basename(filename ? filename : file));
1999 ainfo->content_type = procmime_get_mime_type(file);
2000 if (!ainfo->content_type) {
2001 ainfo->content_type =
2002 g_strdup("application/octet-stream");
2003 ainfo->encoding = ENC_BASE64;
2004 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
2005 ainfo->encoding = procmime_get_encoding_for_file(file);
2007 ainfo->encoding = ENC_BASE64;
2008 ainfo->name = g_strdup(g_basename(filename ? filename : file));
2012 text[COL_MIMETYPE] = ainfo->content_type;
2013 text[COL_SIZE] = to_human_readable(size);
2014 text[COL_NAME] = ainfo->name;
2016 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2017 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2020 #define IS_FIRST_PART_TEXT(info) \
2021 ((info->mime_type == MIME_TEXT || info->mime_type == MIME_TEXT_HTML || \
2022 info->mime_type == MIME_TEXT_ENRICHED) || \
2023 (info->mime_type == MIME_MULTIPART && info->content_type && \
2024 !strcasecmp(info->content_type, "multipart/alternative") && \
2025 (info->children && \
2026 (info->children->mime_type == MIME_TEXT || \
2027 info->children->mime_type == MIME_TEXT_HTML || \
2028 info->children->mime_type == MIME_TEXT_ENRICHED))))
2030 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2037 mimeinfo = procmime_scan_message(msginfo);
2038 if (!mimeinfo) return;
2040 /* skip first text (presumably message body) */
2041 child = mimeinfo->children;
2042 if (!child || IS_FIRST_PART_TEXT(mimeinfo)) {
2043 procmime_mimeinfo_free_all(mimeinfo);
2046 if (IS_FIRST_PART_TEXT(child))
2047 child = child->next;
2049 infile = procmsg_get_message_file_path(msginfo);
2051 while (child != NULL) {
2052 if (child->children || child->mime_type == MIME_MULTIPART) {
2053 child = procmime_mimeinfo_next(child);
2057 outfile = procmime_get_tmp_file_name(child);
2058 if (procmime_get_part(outfile, infile, child) < 0)
2059 g_warning(_("Can't get the part of multipart message."));
2061 compose_attach_append
2063 child->filename ? child->filename : child->name,
2064 child->content_type);
2066 child = child->next;
2070 procmime_mimeinfo_free_all(mimeinfo);
2073 #undef IS_FIRST_PART_TEXT
2075 #define GET_CHAR(pos, buf, len) \
2077 if (text->use_wchar) \
2078 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2080 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2085 #define INDENT_CHARS ">|#"
2086 #define SPACE_CHARS " \t"
2088 static void compose_wrap_line(Compose *compose)
2090 GtkSText *text = GTK_STEXT(compose->text);
2091 gint ch_len, last_ch_len;
2092 gchar cbuf[MB_LEN_MAX], last_ch;
2096 gint p_start, p_end;
2097 gint line_pos, cur_pos;
2098 gint line_len, cur_len;
2100 gtk_stext_freeze(text);
2102 text_len = gtk_stext_get_length(text);
2104 /* check to see if the point is on the paragraph mark (empty line). */
2105 cur_pos = gtk_stext_get_point(text);
2106 GET_CHAR(cur_pos, cbuf, ch_len);
2107 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2109 goto compose_end; /* on the paragraph mark */
2110 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2111 if (ch_len == 1 && *cbuf == '\n')
2112 goto compose_end; /* on the paragraph mark */
2115 /* find paragraph start. */
2116 line_end = quoted = 0;
2117 for (p_start = cur_pos; p_start >= 0; --p_start) {
2118 GET_CHAR(p_start, cbuf, ch_len);
2119 if (ch_len == 1 && *cbuf == '\n') {
2121 goto compose_end; /* quoted part */
2129 && strchr(prefs_common.quote_chars, *cbuf))
2131 else if (ch_len != 1 || !isspace(*cbuf))
2140 /* find paragraph end. */
2142 for (p_end = cur_pos; p_end < text_len; p_end++) {
2143 GET_CHAR(p_end, cbuf, ch_len);
2144 if (ch_len == 1 && *cbuf == '\n') {
2151 if (line_end && ch_len == 1 &&
2152 strchr(prefs_common.quote_chars, *cbuf))
2153 goto compose_end; /* quoted part */
2158 if (p_end >= text_len)
2161 if (p_start >= p_end)
2164 line_len = cur_len = 0;
2168 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2171 GET_CHAR(cur_pos, cbuf, ch_len);
2178 if (ch_len == 1 && isspace(*cbuf))
2181 if (ch_len == 1 && *cbuf == '\n') {
2183 if (last_ch_len == 1 && !isspace(last_ch)) {
2184 if (cur_pos + 1 < p_end) {
2185 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2186 if (ch_len == 1 && !isspace(*cbuf))
2190 gtk_stext_set_point(text, cur_pos + 1);
2191 gtk_stext_backward_delete(text, 1);
2193 gtk_stext_set_point(text, cur_pos);
2194 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2204 last_ch_len = ch_len;
2208 line_pos = cur_pos + 1;
2209 line_len = cur_len + ch_len;
2212 if (cur_len + ch_len > prefs_common.linewrap_len &&
2216 GET_CHAR(line_pos - 1, cbuf, ch_len);
2217 if (ch_len == 1 && isspace(*cbuf)) {
2218 gtk_stext_set_point(text, line_pos);
2219 gtk_stext_backward_delete(text, 1);
2228 gtk_stext_set_point(text, line_pos);
2229 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2233 cur_len = cur_len - line_len + ch_len;
2239 line_pos = cur_pos + 1;
2240 line_len = cur_len + ch_len;
2246 gtk_stext_thaw(text);
2251 /* Darko: used when I debug wrapping */
2252 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2255 gchar cbuf[MB_LEN_MAX];
2257 printf("%d [", pos);
2258 for (i = pos; i < tlen; i++) {
2259 GET_CHAR(i, cbuf, clen);
2260 if (clen < 0) break;
2261 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2263 fwrite(cbuf, clen, 1, stdout);
2271 WAIT_FOR_INDENT_CHAR,
2272 WAIT_FOR_INDENT_CHAR_OR_SPACE
2275 /* return indent length, we allow:
2276 > followed by spaces/tabs
2277 | followed by spaces/tabs
2278 uppercase characters immediately followed by >,
2279 and the repeating sequences of the above */
2280 /* return indent length */
2281 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2284 guint i, ch_len, alnum_cnt = 0;
2285 IndentState state = WAIT_FOR_INDENT_CHAR;
2286 gchar cbuf[MB_LEN_MAX];
2290 for (i = start_pos; i < text_len; i++) {
2291 GET_CHAR(i, cbuf, ch_len);
2295 if (cbuf[0] == '\n')
2298 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2299 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2302 case WAIT_FOR_SPACE:
2303 if (is_space == FALSE)
2305 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2307 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2308 if (is_indent == FALSE && is_space == FALSE &&
2311 if (is_space == TRUE) {
2313 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2314 } else if (is_indent == TRUE) {
2316 state = WAIT_FOR_SPACE;
2319 state = WAIT_FOR_INDENT_CHAR;
2322 case WAIT_FOR_INDENT_CHAR:
2323 if (is_indent == FALSE && !isupper(cbuf[0]))
2325 if (is_indent == TRUE) {
2327 && !strchr(prefs_common.quote_chars, cbuf[0]))
2330 state = WAIT_FOR_SPACE;
2341 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2347 /* insert quotation string when line was wrapped */
2348 static guint ins_quote(GtkSText *text, guint indent_len,
2349 guint prev_line_pos, guint text_len,
2352 guint i, ins_len = 0;
2356 for (i = 0; i < indent_len; i++) {
2357 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2358 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2360 ins_len = indent_len;
2366 /* check if we should join the next line */
2367 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2368 guint prev_ilen, gboolean autowrap)
2370 guint indent_len, ch_len;
2371 gboolean do_join = FALSE;
2372 gchar cbuf[MB_LEN_MAX];
2374 indent_len = get_indent_length(text, start_pos, tlen);
2376 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2377 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2378 if (ch_len > 0 && (cbuf[0] != '\n'))
2385 static void compose_wrap_line_all(Compose *compose)
2387 compose_wrap_line_all_full(compose, FALSE);
2390 #define STEXT_FREEZE() \
2391 if (!frozen) { gtk_stext_freeze(text); frozen = TRUE; }
2393 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2395 GtkSText *text = GTK_STEXT(compose->text);
2397 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2398 gint line_len = 0, cur_len = 0;
2400 gboolean is_new_line = TRUE, do_delete = FALSE;
2402 gboolean linewrap_quote = TRUE;
2403 gboolean set_editable_pos = FALSE;
2404 gint editable_pos = 0;
2405 gboolean frozen = FALSE;
2406 guint linewrap_len = prefs_common.linewrap_len;
2407 gchar *qfmt = prefs_common.quotemark;
2408 gchar cbuf[MB_LEN_MAX];
2410 tlen = gtk_stext_get_length(text);
2412 for (; cur_pos < tlen; cur_pos++) {
2413 /* mark position of new line - needed for quotation wrap */
2416 i_len = get_indent_length(text, cur_pos, tlen);
2418 is_new_line = FALSE;
2421 g_print("new line i_len=%d p_pos=", i_len);
2422 dump_text(text, p_pos, tlen, 1);
2426 GET_CHAR(cur_pos, cbuf, ch_len);
2428 /* fix line length for tabs */
2429 if (ch_len == 1 && *cbuf == '\t') {
2430 guint tab_width = text->default_tab_width;
2431 guint tab_offset = line_len % tab_width;
2434 g_print("found tab at pos=%d line_len=%d ", cur_pos,
2438 line_len += tab_width - tab_offset - 1;
2442 printf("new_len=%d\n", line_len);
2446 /* we have encountered line break */
2447 if (ch_len == 1 && *cbuf == '\n') {
2449 gchar cb[MB_LEN_MAX];
2451 /* should we join the next line */
2452 if ((autowrap || i_len != cur_len) && do_delete &&
2454 (text, cur_pos + 1, tlen, i_len, autowrap))
2460 g_print("found CR at %d do_del is %d next line is ",
2461 cur_pos, do_delete);
2462 dump_text(text, cur_pos + 1, tlen, 1);
2465 /* skip delete if it is continuous URL */
2466 if (do_delete && (line_pos - p_pos <= i_len) &&
2467 gtkut_stext_is_uri_string(text, line_pos, tlen))
2471 g_print("l_len=%d wrap_len=%d do_del=%d\n",
2472 line_len, linewrap_len, do_delete);
2474 /* should we delete to perform smart wrapping */
2475 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 */
2486 ilen = gtkut_stext_str_compare_n
2487 (text, cur_pos, p_pos, i_len,
2490 gtk_stext_forward_delete
2496 GET_CHAR(cur_pos, cb, clen);
2498 /* insert space if it's alphanumeric */
2499 if ((cur_pos != line_pos) &&
2500 ((clen > 1) || isalnum(cb[0]))) {
2501 gtk_stext_insert(text, NULL, NULL,
2506 /* and start over with current line */
2507 cur_pos = p_pos - 1;
2509 line_len = cur_len = 0;
2513 g_print("after delete l_pos=");
2514 dump_text(text, line_pos, tlen, 1);
2519 /* mark new line beginning */
2520 line_pos = cur_pos + 1;
2521 line_len = cur_len = 0;
2532 /* possible line break */
2533 if (ch_len == 1 && isspace(*cbuf)) {
2534 line_pos = cur_pos + 1;
2535 line_len = cur_len + ch_len;
2538 /* are we over wrapping length set in preferences ? */
2539 if (cur_len + ch_len > linewrap_len) {
2543 g_print("should wrap cur_pos=%d ", cur_pos);
2544 dump_text(text, p_pos, tlen, 1);
2545 dump_text(text, line_pos, tlen, 1);
2547 /* force wrapping if it is one long word but not URL */
2548 if (line_pos - p_pos <= i_len)
2549 if (!gtkut_stext_is_uri_string
2550 (text, line_pos, tlen))
2551 line_pos = cur_pos - 1;
2553 g_print("new line_pos=%d\n", line_pos);
2556 GET_CHAR(line_pos - 1, cbuf, clen);
2558 /* if next character is space delete it */
2559 if (clen == 1 && isspace(*cbuf)) {
2560 if (p_pos + i_len != line_pos ||
2561 !gtkut_stext_is_uri_string
2562 (text, line_pos, tlen)) {
2564 /* workaround for correct cursor
2566 if (set_editable_pos == FALSE) {
2567 editable_pos = gtk_editable_get_position(GTK_EDITABLE(text));
2568 if (editable_pos == line_pos)
2569 set_editable_pos = TRUE;
2571 gtk_stext_set_point(text, line_pos);
2572 gtk_stext_backward_delete(text, 1);
2581 /* if it is URL at beginning of line don't wrap */
2582 if (p_pos + i_len == line_pos &&
2583 gtkut_stext_is_uri_string(text, line_pos, tlen)) {
2585 g_print("found URL at ");
2586 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 */
2602 line_len = cur_len = 0;
2603 if (autowrap || i_len > 0)
2608 g_print("after CR insert ");
2609 dump_text(text, line_pos, tlen, 1);
2610 dump_text(text, cur_pos, tlen, 1);
2613 /* should we insert quotation ? */
2614 if (linewrap_quote && i_len) {
2615 /* only if line is not already quoted */
2616 if (!gtkut_stext_str_compare
2617 (text, line_pos, tlen, qfmt)) {
2620 if (line_pos - p_pos > i_len) {
2622 (text, i_len, p_pos,
2627 g_print("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 */
2644 gtk_stext_thaw(text);
2646 if (set_editable_pos && editable_pos <= tlen)
2647 gtk_editable_set_position(GTK_EDITABLE(text), editable_pos);
2653 static void compose_set_title(Compose *compose)
2658 edited = compose->modified ? _(" [Edited]") : "";
2659 if (compose->account && compose->account->address)
2660 str = g_strdup_printf(_("%s - Compose message%s"),
2661 compose->account->address, edited);
2663 str = g_strdup_printf(_("Compose message%s"), edited);
2664 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2669 * compose_current_mail_account:
2671 * Find a current mail account (the currently selected account, or the
2672 * default account, if a news account is currently selected). If a
2673 * mail account cannot be found, display an error message.
2675 * Return value: Mail account, or NULL if not found.
2677 static PrefsAccount *
2678 compose_current_mail_account(void)
2682 if (cur_account && cur_account->protocol != A_NNTP)
2685 ac = account_get_default();
2686 if (!ac || ac->protocol == A_NNTP) {
2687 alertpanel_error(_("Account for sending mail is not specified.\n"
2688 "Please select a mail account before sending."));
2695 static void compose_select_account(Compose *compose, PrefsAccount *account)
2697 GtkWidget *menuitem;
2698 GtkItemFactory *ifactory;
2700 g_return_if_fail(account != NULL);
2702 compose->account = account;
2704 compose_set_title(compose);
2706 ifactory = gtk_item_factory_from_widget(compose->menubar);
2708 if (account->protocol == A_NNTP) {
2709 gtk_widget_show(compose->newsgroups_hbox);
2710 gtk_widget_show(compose->newsgroups_entry);
2711 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
2713 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2714 gtk_check_menu_item_set_active
2715 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2716 gtk_widget_set_sensitive(menuitem, TRUE);
2717 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2718 gtk_check_menu_item_set_active
2719 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2720 gtk_widget_set_sensitive(menuitem, TRUE);
2722 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
2724 gtk_widget_hide(compose->newsgroups_hbox);
2725 gtk_widget_hide(compose->newsgroups_entry);
2726 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
2727 gtk_widget_queue_resize(compose->table_vbox);
2729 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2730 gtk_check_menu_item_set_active
2731 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2732 gtk_widget_set_sensitive(menuitem, FALSE);
2733 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2734 gtk_check_menu_item_set_active
2735 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2736 gtk_widget_set_sensitive(menuitem, FALSE);
2738 menuitem = gtk_item_factory_get_item(ifactory, "/View/Followup to");
2739 gtk_check_menu_item_set_active
2740 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2741 gtk_widget_set_sensitive(menuitem, FALSE);
2744 if (account->set_autocc && account->auto_cc &&
2745 compose->mode != COMPOSE_REEDIT) {
2747 (GTK_ENTRY(compose->cc_entry), account->auto_cc);
2748 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2749 gtk_check_menu_item_set_active
2750 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2752 if (account->set_autobcc) {
2753 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
2754 gtk_check_menu_item_set_active
2755 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2756 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
2757 gtk_entry_set_text(GTK_ENTRY(compose->bcc_entry),
2760 if (account->set_autoreplyto) {
2761 menuitem = gtk_item_factory_get_item(ifactory,
2763 gtk_check_menu_item_set_active
2764 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2765 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
2766 gtk_entry_set_text(GTK_ENTRY(compose->reply_entry),
2767 account->auto_replyto);
2770 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
2771 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2772 prefs_common.show_ruler);
2776 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
2777 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2778 account->default_sign);
2779 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
2780 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2781 account->default_encrypt);
2782 #endif /* USE_GPGME */
2785 gboolean compose_check_for_valid_recipient(Compose *compose) {
2786 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2787 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2788 gboolean recipient_found = FALSE;
2792 /* free to and newsgroup list */
2793 slist_free_strings(compose->to_list);
2794 g_slist_free(compose->to_list);
2795 compose->to_list = NULL;
2797 slist_free_strings(compose->newsgroup_list);
2798 g_slist_free(compose->newsgroup_list);
2799 compose->newsgroup_list = NULL;
2801 /* search header entries for to and newsgroup entries */
2802 for (list = compose->header_list; list; list = list->next) {
2805 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
2806 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2808 if (entry[0] != '\0') {
2809 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2810 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2811 compose->to_list = address_list_append(compose->to_list, entry);
2812 recipient_found = TRUE;
2815 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2816 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2817 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2818 recipient_found = TRUE;
2825 return recipient_found;
2828 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
2832 if (compose_check_for_valid_recipient(compose) == FALSE) {
2833 alertpanel_error(_("Recipient is not specified."));
2837 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2838 if (*str == '\0' && check_subject == TRUE) {
2841 aval = alertpanel(_("Send"),
2842 _("Subject is empty. Send it anyway?"),
2843 _("Yes"), _("No"), NULL);
2844 if (aval != G_ALERTDEFAULT)
2851 gint compose_send(Compose *compose)
2858 if (compose_check_entries(compose, TRUE) == FALSE)
2861 val = compose_queue(compose, &msgnum, &folder);
2863 alertpanel_error(_("Could not queue message for sending"));
2867 msgpath = folder_item_fetch_msg(folder, msgnum);
2868 val = procmsg_send_message_queue(msgpath);
2871 folder_item_remove_msg(folder, msgnum);
2872 folderview_update_item(folder, TRUE);
2877 #if 0 /* compose restructure */
2878 gint compose_send(Compose *compose)
2880 gchar tmp[MAXPATHLEN + 1];
2882 static gboolean lock = FALSE;
2886 g_return_val_if_fail(compose->account != NULL, -1);
2887 g_return_val_if_fail(compose->orig_account != NULL, -1);
2891 if (compose_check_entries(compose, TRUE) == FALSE) {
2896 /* write to temporary file */
2897 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
2898 get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
2900 if (prefs_common.linewrap_at_send)
2901 compose_wrap_line_all(compose);
2903 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2908 if (!compose->to_list && !compose->newsgroup_list) {
2909 g_warning(_("can't get recipient list."));
2915 if (compose->to_list) {
2918 #if 0 /* NEW COMPOSE GUI */
2919 if (compose->account->protocol != A_NNTP)
2920 ac = compose->account;
2921 else if (compose->orig_account->protocol != A_NNTP)
2922 ac = compose->orig_account;
2923 else if (cur_account && cur_account->protocol != A_NNTP)
2926 ac = compose_current_mail_account();
2934 ac = compose->account;
2936 ok = send_message(tmp, ac, compose->to_list);
2937 statusbar_pop_all();
2940 if (ok == 0 && compose->newsgroup_list) {
2943 if (compose->account->protocol == A_NNTP)
2944 folder = FOLDER(compose->account->folder);
2946 folder = FOLDER(compose->orig_account->folder);
2948 ok = news_post(folder, tmp);
2950 alertpanel_error(_("Error occurred while posting the message to %s ."),
2951 compose->account->nntp_server);
2958 /* queue message if failed to send */
2960 if (prefs_common.queue_msg) {
2965 _("Error occurred while sending the message.\n"
2966 "Put this message into queue folder?"),
2967 _("OK"), _("Cancel"), NULL);
2968 if (G_ALERTDEFAULT == val) {
2969 ok = compose_queue(compose, tmp);
2971 alertpanel_error(_("Can't queue the message."));
2974 alertpanel_error(_("Error occurred while sending the message."));
2976 if (compose->mode == COMPOSE_REEDIT) {
2977 compose_remove_reedit_target(compose);
2978 if (compose->targetinfo)
2979 folderview_update_item
2980 (compose->targetinfo->folder, TRUE);
2982 /* save message to outbox */
2983 if (prefs_common.savemsg) {
2986 outbox = account_get_special_folder
2987 (compose->account, F_OUTBOX);
2988 if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
2990 (_("Can't save the message to Sent."));
2992 folderview_update_item(outbox, TRUE);
3002 static gboolean compose_use_attach(Compose *compose) {
3003 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
3006 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3009 gchar buf[BUFFSIZE];
3011 gboolean first_address;
3013 ComposeHeaderEntry *headerentry;
3014 gchar *headerentryname;
3018 debug_print("Writing redirect header\n");
3020 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3021 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3023 first_address = TRUE;
3024 for (list = compose->header_list; list; list = list->next) {
3025 headerentry = ((ComposeHeaderEntry *)list->data);
3026 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3028 if (g_strcasecmp(headerentryname, cc_hdr) == 0
3029 || g_strcasecmp(headerentryname, to_hdr) == 0) {
3030 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3031 Xstrdup_a(str, str, return -1);
3033 if (str[0] != '\0') {
3034 compose_convert_header
3035 (buf, sizeof(buf), str,
3036 strlen("Resent-To") + 2);
3037 if (first_address) {
3038 fprintf(fp, "Resent-To: ");
3039 first_address = FALSE;
3043 fprintf(fp, "%s", buf);
3047 /* if (!first_address) { */
3054 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3056 gchar buf[BUFFSIZE];
3058 /* struct utsname utsbuf; */
3060 g_return_val_if_fail(fp != NULL, -1);
3061 g_return_val_if_fail(compose->account != NULL, -1);
3062 g_return_val_if_fail(compose->account->address != NULL, -1);
3065 get_rfc822_date(buf, sizeof(buf));
3066 fprintf(fp, "Resent-Date: %s\n", buf);
3069 if (compose->account->name && *compose->account->name) {
3070 compose_convert_header
3071 (buf, sizeof(buf), compose->account->name,
3073 fprintf(fp, "Resent-From: %s <%s>\n",
3074 buf, compose->account->address);
3076 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3079 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3081 Xstrdup_a(str, str, return -1);
3084 compose_convert_header(buf, sizeof(buf), str,
3085 strlen("Subject: "));
3086 fprintf(fp, "Subject: %s\n", buf);
3090 /* Resent-Message-ID */
3091 if (compose->account->gen_msgid) {
3092 compose_generate_msgid(compose, buf, sizeof(buf));
3093 fprintf(fp, "Resent-Message-Id: <%s>\n", buf);
3094 compose->msgid = g_strdup(buf);
3097 compose_redirect_write_headers_from_headerlist(compose, fp);
3099 /* separator between header and body */
3105 static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
3110 gchar buf[BUFFSIZE];
3112 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
3113 FILE_OP_ERROR(file, "fopen");
3117 if ((fdest = fopen(file, "wb")) == NULL) {
3118 FILE_OP_ERROR(file, "fopen");
3123 /* chmod for security */
3124 if (change_file_mode_rw(fdest, file) < 0) {
3125 FILE_OP_ERROR(file, "chmod");
3126 g_warning(_("can't change file mode\n"));
3129 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
3130 /* should filter returnpath, delivered-to */
3131 if (g_strncasecmp(buf, "Return-Path:",
3132 strlen("Return-Path:")) == 0 ||
3133 g_strncasecmp(buf, "Delivered-To:",
3134 strlen("Delivered-To:")) == 0 ||
3135 g_strncasecmp(buf, "Received:",
3136 strlen("Received:")) == 0 ||
3137 g_strncasecmp(buf, "Subject:",
3138 strlen("Subject:")) == 0 ||
3139 g_strncasecmp(buf, "X-UIDL:",
3140 strlen("X-UIDL:")) == 0)
3143 if (fputs(buf, fdest) == -1)
3146 if (!prefs_common.redirect_keep_from) {
3147 if (g_strncasecmp(buf, "From:",
3148 strlen("From:")) == 0) {
3149 fputs(" (by way of ", fdest);
3150 if (compose->account->name
3151 && *compose->account->name) {
3152 compose_convert_header
3154 compose->account->name,
3156 fprintf(fdest, "%s <%s>",
3158 compose->account->address);
3160 fprintf(fdest, "%s",
3161 compose->account->address);
3166 if (fputs("\n", fdest) == -1)
3170 compose_redirect_write_headers(compose, fdest);
3172 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3173 if (fwrite(buf, sizeof(gchar), len, fdest) != len) {
3174 FILE_OP_ERROR(file, "fwrite");
3180 if (fclose(fdest) == EOF) {
3181 FILE_OP_ERROR(file, "fclose");
3197 /* interfaces to rfc2015 to keep out the prefs stuff there.
3198 * returns 0 on success and -1 on error. */
3199 static gint compose_create_signers_list(Compose *compose, GSList **pkey_list)
3201 const gchar *key_id = NULL;
3204 switch (compose->account->sign_key) {
3205 case SIGN_KEY_DEFAULT:
3208 case SIGN_KEY_BY_FROM:
3209 key_id = compose->account->address;
3211 case SIGN_KEY_CUSTOM:
3212 key_id = compose->account->sign_key_id;
3218 key_list = rfc2015_create_signers_list(key_id);
3221 alertpanel_error(_("Could not find any key associated with "
3222 "currently selected key id `%s'."), key_id);
3226 *pkey_list = key_list;
3230 /* clearsign message body text */
3231 static gint compose_clearsign_text(Compose *compose, gchar **text)
3236 tmp_file = get_tmp_file();
3237 if (str_write_to_file(*text, tmp_file) < 0) {
3242 if (canonicalize_file_replace(tmp_file) < 0 ||
3243 compose_create_signers_list(compose, &key_list) < 0 ||
3244 rfc2015_clearsign(tmp_file, key_list) < 0) {
3251 *text = file_read_to_str(tmp_file);
3259 #endif /* USE_GPGME */
3261 static gint compose_write_to_file(Compose *compose, const gchar *file,
3268 const gchar *out_codeset;
3269 EncodingType encoding;
3271 if ((fp = fopen(file, "wb")) == NULL) {
3272 FILE_OP_ERROR(file, "fopen");
3276 /* chmod for security */
3277 if (change_file_mode_rw(fp, file) < 0) {
3278 FILE_OP_ERROR(file, "chmod");
3279 g_warning(_("can't change file mode\n"));
3282 /* get all composed text */
3283 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3284 len = strlen(chars);
3285 if (is_ascii_str(chars)) {
3288 out_codeset = CS_US_ASCII;
3289 encoding = ENC_7BIT;
3291 const gchar *src_codeset;
3293 out_codeset = conv_get_outgoing_charset_str();
3294 if (!strcasecmp(out_codeset, CS_US_ASCII))
3295 out_codeset = CS_ISO_8859_1;
3296 encoding = procmime_get_encoding_for_charset(out_codeset);
3300 compose->use_signing && !compose->account->clearsign &&
3301 encoding == ENC_8BIT)
3302 encoding = ENC_BASE64;
3305 src_codeset = conv_get_current_charset_str();
3306 /* if current encoding is US-ASCII, set it the same as
3307 outgoing one to prevent code conversion failure */
3308 if (!strcasecmp(src_codeset, CS_US_ASCII))
3309 src_codeset = out_codeset;
3311 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3312 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3314 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3320 _("Can't convert the character encoding of the message.\n"
3321 "Send it anyway?"), _("Yes"), _("+No"), NULL);
3322 if (aval != G_ALERTDEFAULT) {
3336 if (!is_draft && compose->use_signing && compose->account->clearsign) {
3337 if (compose_clearsign_text(compose, &buf) < 0) {
3338 g_warning("clearsign failed\n");
3348 if (compose_write_headers
3349 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3350 g_warning(_("can't write headers\n"));
3357 if (compose_use_attach(compose)) {
3359 /* This prolog message is ignored by mime software and
3360 * because it would make our signing/encryption task
3361 * tougher, we don't emit it in that case */
3362 if (!compose->use_signing && !compose->use_encryption)
3364 fputs("This is a multi-part message in MIME format.\n", fp);
3366 fprintf(fp, "\n--%s\n", compose->boundary);
3367 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3369 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3370 procmime_get_encoding_str(encoding));
3376 if (encoding == ENC_BASE64) {
3377 gchar outbuf[B64_BUFFSIZE];
3380 for (i = 0; i < len; i += B64_LINE_SIZE) {
3381 l = MIN(B64_LINE_SIZE, len - i);
3382 base64_encode(outbuf, buf + i, l);
3386 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3387 FILE_OP_ERROR(file, "fwrite");
3395 if (compose_use_attach(compose))
3396 compose_write_attach(compose, fp);
3398 if (fclose(fp) == EOF) {
3399 FILE_OP_ERROR(file, "fclose");
3408 if ((compose->use_signing && !compose->account->clearsign) ||
3409 compose->use_encryption) {
3410 if (canonicalize_file_replace(file) < 0) {
3416 if (compose->use_signing && !compose->account->clearsign) {
3419 if (compose_create_signers_list(compose, &key_list) < 0 ||
3420 rfc2015_sign(file, key_list) < 0) {
3425 if (compose->use_encryption) {
3426 if (rfc2015_encrypt(file, compose->to_list,
3427 compose->account->ascii_armored) < 0) {
3432 #endif /* USE_GPGME */
3437 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3443 if ((fp = fopen(file, "wb")) == NULL) {
3444 FILE_OP_ERROR(file, "fopen");
3448 /* chmod for security */
3449 if (change_file_mode_rw(fp, file) < 0) {
3450 FILE_OP_ERROR(file, "chmod");
3451 g_warning(_("can't change file mode\n"));
3454 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3457 len = strlen(chars);
3458 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3459 FILE_OP_ERROR(file, "fwrite");
3468 if (fclose(fp) == EOF) {
3469 FILE_OP_ERROR(file, "fclose");
3476 static gint compose_remove_reedit_target(Compose *compose)
3479 MsgInfo *msginfo = compose->targetinfo;
3481 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3482 if (!msginfo) return -1;
3484 item = msginfo->folder;
3485 g_return_val_if_fail(item != NULL, -1);
3487 if (procmsg_msg_exist(msginfo) &&
3488 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3489 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3490 g_warning(_("can't remove the old message\n"));
3498 void compose_remove_draft(Compose *compose)
3501 MsgInfo *msginfo = compose->targetinfo;
3502 drafts = account_get_special_folder(compose->account, F_DRAFT);
3504 if (procmsg_msg_exist(msginfo)) {
3505 folder_item_remove_msg(drafts, msginfo->msgnum);
3506 folderview_update_item(drafts, TRUE);
3511 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3513 return compose_queue_sub (compose, msgnum, item, FALSE);
3515 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3521 gchar buf[BUFFSIZE];
3523 static gboolean lock = FALSE;
3524 PrefsAccount *mailac = NULL, *newsac = NULL;
3526 debug_print("queueing message...\n");
3527 g_return_val_if_fail(compose->account != NULL, -1);
3528 g_return_val_if_fail(compose->orig_account != NULL, -1);
3532 if (compose_check_entries(compose, check_subject) == FALSE) {
3537 if (!compose->to_list && !compose->newsgroup_list) {
3538 g_warning(_("can't get recipient list."));
3543 if (compose->to_list) {
3544 if (compose->account->protocol != A_NNTP)
3545 mailac = compose->account;
3546 else if (compose->orig_account->protocol != A_NNTP)
3547 mailac = compose->orig_account;
3548 else if (cur_account && cur_account->protocol != A_NNTP)
3549 mailac = cur_account;
3550 else if (!(mailac = compose_current_mail_account())) {
3552 alertpanel_error(_("No account for sending mails available!"));
3557 if (compose->newsgroup_list) {
3558 if (compose->account->protocol == A_NNTP)
3559 newsac = compose->account;
3560 else if (!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3562 alertpanel_error(_("No account for posting news available!"));
3567 if (prefs_common.linewrap_at_send)
3568 compose_wrap_line_all(compose);
3570 /* write to temporary file */
3571 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3572 G_DIR_SEPARATOR, (gint)compose);
3574 if (compose->redirect_filename != NULL) {
3575 if (compose_redirect_write_to_file(compose, tmp2) < 0) {
3582 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3589 /* add queue header */
3590 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3591 G_DIR_SEPARATOR, (gint)compose);
3592 if ((fp = fopen(tmp, "wb")) == NULL) {
3593 FILE_OP_ERROR(tmp, "fopen");
3597 if ((src_fp = fopen(tmp2, "rb")) == NULL) {
3598 FILE_OP_ERROR(tmp2, "fopen");
3606 if (change_file_mode_rw(fp, tmp) < 0) {
3607 FILE_OP_ERROR(tmp, "chmod");
3608 g_warning(_("can't change file mode\n"));
3611 /* queueing variables */
3612 fprintf(fp, "AF:\n");
3613 fprintf(fp, "NF:0\n");
3614 fprintf(fp, "PS:10\n");
3615 fprintf(fp, "SRH:1\n");
3616 fprintf(fp, "SFN:\n");
3617 fprintf(fp, "DSR:\n");
3619 fprintf(fp, "MID:<%s>\n", compose->msgid);
3621 fprintf(fp, "MID:\n");
3622 fprintf(fp, "CFG:\n");
3623 fprintf(fp, "PT:0\n");
3624 fprintf(fp, "S:%s\n", compose->account->address);
3625 fprintf(fp, "RQ:\n");
3627 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3629 fprintf(fp, "SSV:\n");
3631 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3633 fprintf(fp, "NSV:\n");
3634 fprintf(fp, "SSH:\n");
3635 /* write recepient list */
3637 if (compose->to_list) {
3638 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3639 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3640 fprintf(fp, ",<%s>", (gchar *)cur->data);
3643 /* write newsgroup list */
3645 if (compose->newsgroup_list) {
3646 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3647 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3648 fprintf(fp, ",%s", (gchar *)cur->data);
3651 /* Sylpheed account IDs */
3653 fprintf(fp, "MAID:%d\n", mailac->account_id);
3656 fprintf(fp, "NAID:%d\n", newsac->account_id);
3658 /* Save copy folder */
3659 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3660 gchar *savefolderid;
3662 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3663 fprintf(fp, "SCF:%s\n", savefolderid);
3664 g_free(savefolderid);
3666 /* Message-ID of message replying to */
3667 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
3670 folderid = folder_item_get_identifier(compose->replyinfo->folder);
3671 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
3676 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3677 if (fputs(buf, fp) == EOF) {
3678 FILE_OP_ERROR(tmp, "fputs");
3689 if (fclose(fp) == EOF) {
3690 FILE_OP_ERROR(tmp, "fclose");
3698 queue = account_get_special_folder(compose->account, F_QUEUE);
3700 g_warning(_("can't find queue folder\n"));
3705 folder_item_scan(queue);
3706 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3707 g_warning(_("can't queue the message\n"));
3717 if (compose->mode == COMPOSE_REEDIT) {
3718 compose_remove_reedit_target(compose);
3719 if (compose->targetinfo &&
3720 compose->targetinfo->folder != queue)
3721 folderview_update_item
3722 (compose->targetinfo->folder, TRUE);
3725 folderview_update_item(queue, TRUE);
3727 if ((msgnum != NULL) && (item != NULL)) {
3735 static void compose_write_attach(Compose *compose, FILE *fp)
3738 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3741 gchar filename[BUFFSIZE];
3744 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3746 gchar buf[BUFFSIZE];
3747 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3749 if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
3750 g_warning(_("Can't open file %s\n"), ainfo->file);
3754 fprintf(fp, "\n--%s\n", compose->boundary);
3756 if (!strcmp2(ainfo->content_type, "message/rfc822")) {