2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2003 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"
95 #include "quoted-printable.h"
100 #include "alertpanel.h"
101 #include "manage_window.h"
102 #include "gtkshruler.h"
104 #include "addr_compl.h"
105 #include "quote_fmt.h"
106 #include "template.h"
108 #include "foldersel.h"
112 # include "rfc2015.h"
122 #define N_ATTACH_COLS 3
126 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
127 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
128 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
129 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
130 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
131 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
132 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
133 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
134 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
135 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
136 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
137 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
138 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
139 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
140 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END
141 } ComposeCallGtkSTextAction;
145 PRIORITY_HIGHEST = 1,
152 #define B64_LINE_SIZE 57
153 #define B64_BUFFSIZE 77
155 #define MAX_REFERENCES_LEN 999
157 static GdkColor quote_color = {0, 0, 0, 0xbfff};
159 static GList *compose_list = NULL;
161 Compose *compose_generic_new (PrefsAccount *account,
164 GPtrArray *attach_files);
166 static Compose *compose_create (PrefsAccount *account,
169 static GtkWidget *compose_account_option_menu_create
171 static void compose_set_template_menu (Compose *compose);
172 static void compose_template_apply (Compose *compose,
175 static void compose_destroy (Compose *compose);
177 static void compose_entries_set (Compose *compose,
178 const gchar *mailto);
179 static gint compose_parse_header (Compose *compose,
181 static gchar *compose_parse_references (const gchar *ref,
184 static gchar *compose_quote_fmt (Compose *compose,
190 static void compose_reply_set_entry (Compose *compose,
196 followup_and_reply_to);
197 static void compose_reedit_set_entry (Compose *compose,
199 static void compose_insert_sig (Compose *compose);
200 static void compose_insert_file (Compose *compose,
202 static void compose_attach_append (Compose *compose,
205 const gchar *content_type);
206 static void compose_attach_parts (Compose *compose,
208 static void compose_wrap_line (Compose *compose);
209 static void compose_wrap_line_all (Compose *compose);
210 static void compose_wrap_line_all_full (Compose *compose,
212 static void compose_set_title (Compose *compose);
213 static void compose_select_account (Compose *compose,
214 PrefsAccount *account);
216 static PrefsAccount *compose_current_mail_account(void);
217 /* static gint compose_send (Compose *compose); */
218 static gboolean compose_check_for_valid_recipient
220 static gboolean compose_check_entries (Compose *compose,
221 gboolean check_subject);
222 static gint compose_write_to_file (Compose *compose,
225 static gint compose_write_body_to_file (Compose *compose,
227 static gint compose_remove_reedit_target (Compose *compose);
228 void compose_remove_draft (Compose *compose);
229 static gint compose_queue (Compose *compose,
232 static gint compose_queue_sub (Compose *compose,
235 gboolean check_subject);
236 static void compose_write_attach (Compose *compose,
238 static gint compose_write_headers (Compose *compose,
240 const gchar *charset,
241 EncodingType encoding,
244 static void compose_convert_header (gchar *dest,
248 static void compose_generate_msgid (Compose *compose,
252 static void compose_attach_info_free (AttachInfo *ainfo);
253 static void compose_attach_remove_selected (Compose *compose);
255 static void compose_attach_property (Compose *compose);
256 static void compose_attach_property_create (gboolean *cancelled);
257 static void attach_property_ok (GtkWidget *widget,
258 gboolean *cancelled);
259 static void attach_property_cancel (GtkWidget *widget,
260 gboolean *cancelled);
261 static gint attach_property_delete_event (GtkWidget *widget,
263 gboolean *cancelled);
264 static void attach_property_key_pressed (GtkWidget *widget,
266 gboolean *cancelled);
268 static void compose_exec_ext_editor (Compose *compose);
269 static gint compose_exec_ext_editor_real (const gchar *file);
270 static gboolean compose_ext_editor_kill (Compose *compose);
271 static void compose_input_cb (gpointer data,
273 GdkInputCondition condition);
274 static void compose_set_ext_editor_sensitive (Compose *compose,
277 static void compose_undo_state_changed (UndoMain *undostruct,
282 static gint calc_cursor_xpos (GtkSText *text,
286 static void compose_create_header_entry (Compose *compose);
287 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
288 static void compose_update_priority_menu_item(Compose * compose);
290 /* callback functions */
292 static gboolean compose_edit_size_alloc (GtkEditable *widget,
293 GtkAllocation *allocation,
294 GtkSHRuler *shruler);
295 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_paste_as_quote_cb (Compose *compose);
353 static void compose_allsel_cb (Compose *compose);
355 static void compose_gtk_stext_action_cb (Compose *compose,
356 ComposeCallGtkSTextAction action);
358 static void compose_grab_focus_cb (GtkWidget *widget,
361 static void compose_changed_cb (GtkEditable *editable,
363 static void compose_button_press_cb (GtkWidget *widget,
364 GdkEventButton *event,
367 static void compose_key_press_cb (GtkWidget *widget,
373 static void compose_toggle_to_cb (gpointer data,
376 static void compose_toggle_cc_cb (gpointer data,
379 static void compose_toggle_bcc_cb (gpointer data,
382 static void compose_toggle_replyto_cb (gpointer data,
385 static void compose_toggle_followupto_cb(gpointer data,
388 static void compose_toggle_attach_cb (gpointer data,
392 static void compose_toggle_ruler_cb (gpointer data,
396 static void compose_toggle_sign_cb (gpointer data,
399 static void compose_toggle_encrypt_cb (gpointer data,
402 static void compose_set_gnupg_mode_cb (gpointer data,
405 static void compose_update_gnupg_mode_menu_item(Compose * compose);
406 static void activate_gnupg_mode (Compose *compose,
407 PrefsAccount *account);
409 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
411 static void compose_set_priority_cb (gpointer data,
415 static void compose_attach_drag_received_cb (GtkWidget *widget,
416 GdkDragContext *drag_context,
419 GtkSelectionData *data,
423 static void compose_insert_drag_received_cb (GtkWidget *widget,
424 GdkDragContext *drag_context,
427 GtkSelectionData *data,
433 static void to_activated (GtkWidget *widget,
435 static void newsgroups_activated (GtkWidget *widget,
437 static void cc_activated (GtkWidget *widget,
439 static void bcc_activated (GtkWidget *widget,
441 static void replyto_activated (GtkWidget *widget,
443 static void followupto_activated (GtkWidget *widget,
445 static void subject_activated (GtkWidget *widget,
449 static void text_activated (GtkWidget *widget,
451 static void text_inserted (GtkWidget *widget,
456 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
457 gboolean to_all, gboolean to_ml,
459 gboolean followup_and_reply_to,
462 void compose_headerentry_changed_cb (GtkWidget *entry,
463 ComposeHeaderEntry *headerentry);
464 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
466 ComposeHeaderEntry *headerentry);
468 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
471 static void compose_check_all (Compose *compose);
472 static void compose_highlight_all (Compose *compose);
473 static void compose_check_backwards (Compose *compose);
474 static void compose_check_forwards_go (Compose *compose);
477 static gboolean compose_send_control_enter (Compose *compose);
479 static GtkItemFactoryEntry compose_popup_entries[] =
481 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
482 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
483 {N_("/---"), NULL, NULL, 0, "<Separator>"},
484 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
487 static GtkItemFactoryEntry compose_entries[] =
489 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
490 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
491 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
492 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
493 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
494 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
496 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
497 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
498 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
499 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
500 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
501 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
502 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
503 {N_("/_Edit/Paste as _quotation"),
504 NULL, compose_paste_as_quote_cb, 0, NULL},
505 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
506 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
507 {N_("/_Edit/A_dvanced/Move a character backward"),
509 compose_gtk_stext_action_cb,
510 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
512 {N_("/_Edit/A_dvanced/Move a character forward"),
514 compose_gtk_stext_action_cb,
515 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
517 {N_("/_Edit/A_dvanced/Move a word backward"),
519 compose_gtk_stext_action_cb,
520 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
522 {N_("/_Edit/A_dvanced/Move a word forward"),
524 compose_gtk_stext_action_cb,
525 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
527 {N_("/_Edit/A_dvanced/Move to beginning of line"),
528 NULL, /* "<control>A" */
529 compose_gtk_stext_action_cb,
530 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
532 {N_("/_Edit/A_dvanced/Move to end of line"),
534 compose_gtk_stext_action_cb,
535 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
537 {N_("/_Edit/A_dvanced/Move to previous line"),
539 compose_gtk_stext_action_cb,
540 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
542 {N_("/_Edit/A_dvanced/Move to next line"),
544 compose_gtk_stext_action_cb,
545 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
547 {N_("/_Edit/A_dvanced/Delete a character backward"),
549 compose_gtk_stext_action_cb,
550 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
552 {N_("/_Edit/A_dvanced/Delete a character forward"),
554 compose_gtk_stext_action_cb,
555 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
557 {N_("/_Edit/A_dvanced/Delete a word backward"),
558 NULL, /* "<control>W" */
559 compose_gtk_stext_action_cb,
560 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
562 {N_("/_Edit/A_dvanced/Delete a word forward"),
563 NULL, /* "<alt>D", */
564 compose_gtk_stext_action_cb,
565 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
567 {N_("/_Edit/A_dvanced/Delete line"),
569 compose_gtk_stext_action_cb,
570 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
572 {N_("/_Edit/A_dvanced/Delete entire line"),
574 compose_gtk_stext_action_cb,
575 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
577 {N_("/_Edit/A_dvanced/Delete to end of line"),
579 compose_gtk_stext_action_cb,
580 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
582 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
583 {N_("/_Edit/_Wrap current paragraph"),
584 "<control>L", compose_wrap_line, 0, NULL},
585 {N_("/_Edit/Wrap all long _lines"),
586 "<control><alt>L", compose_wrap_line_all, 0, NULL},
587 {N_("/_Edit/Edit with e_xternal editor"),
588 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
590 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
591 {N_("/_Spelling/_Check all or check selection"),
592 NULL, compose_check_all, 0, NULL},
593 {N_("/_Spelling/_Highlight all misspelled words"),
594 NULL, compose_highlight_all, 0, NULL},
595 {N_("/_Spelling/Check _backwards misspelled word"),
596 NULL, compose_check_backwards , 0, NULL},
597 {N_("/_Spelling/_Forward to next misspelled word"),
598 NULL, compose_check_forwards_go, 0, NULL},
599 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
600 {N_("/_Spelling/_Spelling Configuration"),
601 NULL, NULL, 0, "<Branch>"},
603 #if 0 /* NEW COMPOSE GUI */
604 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
605 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
606 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
607 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
608 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
609 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
610 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
611 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
612 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
613 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
614 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
616 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
617 {N_("/_Message/_Send"), "<control>Return",
618 compose_send_cb, 0, NULL},
619 {N_("/_Message/Send _later"), "<shift><control>S",
620 compose_send_later_cb, 0, NULL},
621 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
622 {N_("/_Message/Save to _draft folder"),
623 "<shift><control>D", compose_draft_cb, 0, NULL},
624 {N_("/_Message/Save and _keep editing"),
625 "<control>S", compose_draft_cb, 1, NULL},
626 #if 0 /* NEW COMPOSE GUI */
627 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
628 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
629 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
630 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
631 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
632 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
633 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
634 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
635 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
638 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
639 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
640 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
641 {N_("/_Message/Mode/MIME"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_DETACH, "<RadioItem>"},
642 {N_("/_Message/Mode/Inline"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_INLINE, "/Message/Mode/MIME"},
643 #endif /* USE_GPGME */
644 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
645 {N_("/_Message/_Priority"), NULL, NULL, 0, "<Branch>"},
646 {N_("/_Message/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
647 {N_("/_Message/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
648 {N_("/_Message/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
649 {N_("/_Message/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
650 {N_("/_Message/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
651 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
652 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
653 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
654 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
655 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
656 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
657 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
658 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
659 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
662 static GtkTargetEntry compose_mime_types[] =
664 {"text/uri-list", 0, 0}
667 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
668 GPtrArray *attach_files)
670 return compose_generic_new(account, mailto, NULL, attach_files);
673 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
675 return compose_generic_new(account, NULL, item, NULL);
678 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
679 GPtrArray *attach_files)
683 GtkItemFactory *ifactory;
684 gboolean grab_focus_on_last = TRUE;
686 if (item && item->prefs && item->prefs->enable_default_account)
687 account = account_find_from_id(item->prefs->default_account);
689 if (!account) account = cur_account;
690 g_return_val_if_fail(account != NULL, NULL);
692 compose = compose_create(account, COMPOSE_NEW);
693 ifactory = gtk_item_factory_from_widget(compose->menubar);
695 compose->replyinfo = NULL;
696 compose->fwdinfo = NULL;
698 text = GTK_STEXT(compose->text);
699 gtk_stext_freeze(text);
701 if (account->auto_sig)
702 compose_insert_sig(compose);
703 gtk_editable_set_position(GTK_EDITABLE(text), 0);
704 gtk_stext_set_point(text, 0);
706 gtk_stext_thaw(text);
708 if (account->protocol != A_NNTP) {
709 if (mailto && *mailto != '\0') {
710 compose_entries_set(compose, mailto);
712 } else if (item && item->prefs->enable_default_to) {
713 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
714 compose_entry_select(compose, item->prefs->default_to);
715 grab_focus_on_last = FALSE;
717 if (item && item->ret_rcpt) {
718 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
722 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
725 * CLAWS: just don't allow return receipt request, even if the user
726 * may want to send an email. simple but foolproof.
728 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
735 for (i = 0; i < attach_files->len; i++) {
736 file = g_ptr_array_index(attach_files, i);
737 compose_attach_append(compose, file, file, NULL);
741 compose_show_first_last_header(compose, TRUE);
743 /* Set save folder */
744 if (item && item->prefs && item->prefs->save_copy_to_folder) {
745 gchar *folderidentifier;
747 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
748 folderidentifier = folder_item_get_identifier(item);
749 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
750 g_free(folderidentifier);
753 /* Grab focus on last header only if no default_to was set */
754 if (grab_focus_on_last)
755 gtk_widget_grab_focus(compose->header_last->entry);
757 if (prefs_common.auto_exteditor)
758 compose_exec_ext_editor(compose);
764 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
765 const gchar *followupto, gchar * to)
769 if (!account) account = cur_account;
770 g_return_val_if_fail(account != NULL, NULL);
771 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
773 compose = compose_create(account, COMPOSE_NEW);
775 if (prefs_common.auto_sig)
776 compose_insert_sig(compose);
777 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
778 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
780 compose_entry_append(compose, to, COMPOSE_TO);
781 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
782 gtk_widget_grab_focus(compose->subject_entry);
788 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
789 gboolean to_ml, gboolean to_sender,
792 compose_generic_reply(msginfo, quote, to_all, to_ml,
793 to_sender, FALSE, body);
796 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
801 compose_generic_reply(msginfo, quote, to_all, FALSE,
802 to_sender, TRUE, body);
805 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
806 gboolean to_all, gboolean to_ml,
808 gboolean followup_and_reply_to,
812 PrefsAccount *account = NULL;
813 PrefsAccount *reply_account;
816 g_return_if_fail(msginfo != NULL);
817 g_return_if_fail(msginfo->folder != NULL);
819 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
821 g_return_if_fail(account != NULL);
823 if (to_sender && account->protocol == A_NNTP &&
824 !followup_and_reply_to) {
826 account_find_from_address(account->address);
828 reply_account = compose_current_mail_account();
832 reply_account = account;
834 compose = compose_create(account, COMPOSE_REPLY);
836 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
837 if (!compose->replyinfo)
838 compose->replyinfo = procmsg_msginfo_copy(msginfo);
840 if (msginfo->folder && msginfo->folder->ret_rcpt) {
841 GtkItemFactory *ifactory;
843 ifactory = gtk_item_factory_from_widget(compose->menubar);
844 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
847 /* Set save folder */
848 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
849 gchar *folderidentifier;
851 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
852 folderidentifier = folder_item_get_identifier(msginfo->folder);
853 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
854 g_free(folderidentifier);
857 if (compose_parse_header(compose, msginfo) < 0) return;
858 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
859 to_sender, followup_and_reply_to);
860 compose_show_first_last_header(compose, TRUE);
862 text = GTK_STEXT(compose->text);
863 gtk_stext_freeze(text);
869 if (prefs_common.quotemark && *prefs_common.quotemark)
870 qmark = prefs_common.quotemark;
874 quote_str = compose_quote_fmt(compose, compose->replyinfo,
875 prefs_common.quotefmt,
879 if (account->auto_sig)
880 compose_insert_sig(compose);
882 if (quote && prefs_common.linewrap_quote)
883 compose_wrap_line_all(compose);
885 gtk_editable_set_position(GTK_EDITABLE(text), 0);
886 gtk_stext_set_point(text, 0);
888 gtk_stext_thaw(text);
889 gtk_widget_grab_focus(compose->text);
891 if (prefs_common.auto_exteditor)
892 compose_exec_ext_editor(compose);
895 #define INSERT_FW_HEADER(var, hdr) \
896 if (msginfo->var && *msginfo->var) { \
897 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
898 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
899 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
902 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
903 gboolean as_attach, const gchar *body)
908 g_return_val_if_fail(msginfo != NULL, NULL);
909 g_return_val_if_fail(msginfo->folder != NULL, NULL);
911 if (msginfo->folder->prefs->enable_default_account)
912 account = account_find_from_id(msginfo->folder->prefs->default_account);
914 account = msginfo->folder->folder->account;
915 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
917 Xstrdup_a(to, msginfo->to, return NULL);
919 account = account_find_from_address(to);
922 if (!account && prefs_common.forward_account_autosel) {
924 if (!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
926 account = account_find_from_address(cc);
930 if (account == NULL) {
931 account = cur_account;
933 account = msginfo->folder->folder->account;
934 if (!account) account = cur_account;
937 g_return_val_if_fail(account != NULL, NULL);
939 compose = compose_create(account, COMPOSE_FORWARD);
941 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
942 if (!compose->fwdinfo)
943 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
945 if (msginfo->subject && *msginfo->subject) {
946 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
947 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
951 text = GTK_STEXT(compose->text);
952 gtk_stext_freeze(text);
958 msgfile = procmsg_get_message_file_path(msginfo);
959 if (!is_file_exist(msgfile))
960 g_warning("%s: file not exist\n", msgfile);
962 compose_attach_append(compose, msgfile, msgfile,
969 MsgInfo *full_msginfo;
971 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
973 full_msginfo = procmsg_msginfo_copy(msginfo);
975 if (prefs_common.fw_quotemark &&
976 *prefs_common.fw_quotemark)
977 qmark = prefs_common.fw_quotemark;
981 quote_str = compose_quote_fmt(compose, full_msginfo,
982 prefs_common.fw_quotefmt,
984 compose_attach_parts(compose, msginfo);
986 procmsg_msginfo_free(full_msginfo);
989 if (account->auto_sig)
990 compose_insert_sig(compose);
992 if (prefs_common.linewrap_quote)
993 compose_wrap_line_all(compose);
995 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
996 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
998 gtk_stext_thaw(text);
999 #if 0 /* NEW COMPOSE GUI */
1000 if (account->protocol != A_NNTP)
1001 gtk_widget_grab_focus(compose->to_entry);
1003 gtk_widget_grab_focus(compose->newsgroups_entry);
1005 gtk_widget_grab_focus(compose->header_last->entry);
1007 if (prefs_common.auto_exteditor)
1008 compose_exec_ext_editor(compose);
1011 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1012 gchar *folderidentifier;
1014 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1015 folderidentifier = folder_item_get_identifier(msginfo->folder);
1016 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1017 g_free(folderidentifier);
1023 #undef INSERT_FW_HEADER
1025 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1032 g_return_val_if_fail(msginfo_list != NULL, NULL);
1034 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1035 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1039 if (account == NULL) {
1040 account = cur_account;
1042 account = msginfo->folder->folder->account;
1043 if (!account) account = cur_account;
1046 g_return_val_if_fail(account != NULL, NULL);
1048 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1049 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1050 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1053 compose = compose_create(account, COMPOSE_FORWARD);
1055 text = GTK_STEXT(compose->text);
1056 gtk_stext_freeze(text);
1058 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1059 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1060 if (!is_file_exist(msgfile))
1061 g_warning("%s: file not exist\n", msgfile);
1063 compose_attach_append(compose, msgfile, msgfile,
1068 if (account->auto_sig)
1069 compose_insert_sig(compose);
1071 if (prefs_common.linewrap_quote)
1072 compose_wrap_line_all(compose);
1074 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1075 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1077 gtk_stext_thaw(text);
1078 gtk_widget_grab_focus(compose->header_last->entry);
1080 #if 0 /* NEW COMPOSE GUI */
1081 if (account->protocol != A_NNTP)
1082 gtk_widget_grab_focus(compose->to_entry);
1084 gtk_widget_grab_focus(compose->newsgroups_entry);
1090 void compose_reedit(MsgInfo *msginfo)
1093 PrefsAccount *account = NULL;
1096 gchar buf[BUFFSIZE];
1098 g_return_if_fail(msginfo != NULL);
1099 g_return_if_fail(msginfo->folder != NULL);
1101 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1102 gchar queueheader_buf[BUFFSIZE];
1105 /* Select Account from queue headers */
1106 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1107 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1108 id = atoi(&queueheader_buf[22]);
1109 account = account_find_from_id(id);
1111 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1112 sizeof(queueheader_buf), "NAID:")) {
1113 id = atoi(&queueheader_buf[5]);
1114 account = account_find_from_id(id);
1116 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1117 sizeof(queueheader_buf), "MAID:")) {
1118 id = atoi(&queueheader_buf[5]);
1119 account = account_find_from_id(id);
1121 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1122 sizeof(queueheader_buf), "S:")) {
1123 account = account_find_from_address(queueheader_buf);
1126 account = msginfo->folder->folder->account;
1128 if (!account && prefs_common.reedit_account_autosel) {
1129 gchar from[BUFFSIZE];
1130 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1131 extract_address(from);
1132 account = account_find_from_address(from);
1135 if (!account) account = cur_account;
1136 g_return_if_fail(account != NULL);
1138 compose = compose_create(account, COMPOSE_REEDIT);
1139 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1141 if (msginfo->folder->stype == F_QUEUE
1142 || msginfo->folder->stype == F_DRAFT) {
1143 gchar queueheader_buf[BUFFSIZE];
1145 /* Set message save folder */
1146 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1149 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1150 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1151 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1155 if (compose_parse_header(compose, msginfo) < 0) return;
1156 compose_reedit_set_entry(compose, msginfo);
1158 text = GTK_STEXT(compose->text);
1159 gtk_stext_freeze(text);
1161 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1162 g_warning("Can't get text part\n");
1164 while (fgets(buf, sizeof(buf), fp) != NULL) {
1166 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1170 compose_attach_parts(compose, msginfo);
1172 gtk_stext_thaw(text);
1173 gtk_widget_grab_focus(compose->text);
1175 if (prefs_common.auto_exteditor)
1176 compose_exec_ext_editor(compose);
1179 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1183 GtkItemFactory *ifactory;
1185 g_return_val_if_fail(msginfo != NULL, NULL);
1188 account = cur_account;
1189 g_return_val_if_fail(account != NULL, NULL);
1191 compose = compose_create(account, COMPOSE_REDIRECT);
1192 ifactory = gtk_item_factory_from_widget(compose->menubar);
1194 compose->replyinfo = NULL;
1195 compose->fwdinfo = NULL;
1197 compose_show_first_last_header(compose, TRUE);
1199 gtk_widget_grab_focus(compose->header_last->entry);
1201 filename = procmsg_get_message_file(msginfo);
1202 if (filename == NULL)
1205 compose->redirect_filename = filename;
1207 compose_attach_parts(compose, msginfo);
1209 if (msginfo->subject)
1210 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1212 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1214 gtk_stext_freeze(GTK_STEXT(compose->text));
1215 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1216 gtk_editable_set_editable(GTK_EDITABLE(compose->text), FALSE);
1217 gtk_stext_thaw(GTK_STEXT(compose->text));
1219 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1220 menu_set_sensitive(ifactory, "/Add...", FALSE);
1221 menu_set_sensitive(ifactory, "/Remove", FALSE);
1222 menu_set_sensitive(ifactory, "/Property...", FALSE);
1224 ifactory = gtk_item_factory_from_widget(compose->menubar);
1225 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
1226 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
1227 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
1228 menu_set_sensitive(ifactory, "/Edit", FALSE);
1229 menu_set_sensitive(ifactory, "/Message/Save to draft folder", FALSE);
1230 menu_set_sensitive(ifactory, "/Message/Save and keep editing", FALSE);
1232 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
1233 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
1234 menu_set_sensitive(ifactory, "/Message/Mode/MIME", FALSE);
1235 menu_set_sensitive(ifactory, "/Message/Mode/Inline", FALSE);
1237 menu_set_sensitive(ifactory, "/Message/Priority", FALSE);
1238 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
1239 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1240 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1242 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1243 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1244 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1245 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1246 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1247 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, FALSE);
1252 GList *compose_get_compose_list(void)
1254 return compose_list;
1257 void compose_entry_append(Compose *compose, const gchar *address,
1258 ComposeEntryType type)
1262 if (!address || *address == '\0') return;
1264 #if 0 /* NEW COMPOSE GUI */
1267 entry = GTK_ENTRY(compose->cc_entry);
1270 entry = GTK_ENTRY(compose->bcc_entry);
1272 case COMPOSE_NEWSGROUPS:
1273 entry = GTK_ENTRY(compose->newsgroups_entry);
1277 entry = GTK_ENTRY(compose->to_entry);
1281 text = gtk_entry_get_text(entry);
1283 gtk_entry_append_text(entry, ", ");
1284 gtk_entry_append_text(entry, address);
1292 header = N_("Bcc:");
1294 case COMPOSE_REPLYTO:
1295 header = N_("Reply-To:");
1297 case COMPOSE_NEWSGROUPS:
1298 header = N_("Newsgroups:");
1300 case COMPOSE_FOLLOWUPTO:
1301 header = N_( "Followup-To:");
1308 header = prefs_common.trans_hdr ? gettext(header) : header;
1310 compose_add_header_entry(compose, header, (gchar *)address);
1313 void compose_entry_select (Compose *compose, const gchar *mailto)
1315 GSList *header_list;
1317 for (header_list = compose->header_list; header_list != NULL; header_list = header_list->next) {
1318 GtkEntry * entry = GTK_ENTRY(((ComposeHeaderEntry *)header_list->data)->entry);
1320 if (gtk_entry_get_text(entry) && !g_strcasecmp(gtk_entry_get_text(entry), mailto)) {
1321 gtk_entry_select_region(entry, 0, -1);
1322 gtk_widget_grab_focus(GTK_WIDGET(entry));
1327 void compose_toolbar_cb(gint action, gpointer data)
1329 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1330 Compose *compose = (Compose*)toolbar_item->parent;
1332 g_return_if_fail(compose != NULL);
1336 compose_send_cb(compose, 0, NULL);
1339 compose_send_later_cb(compose, 0, NULL);
1342 compose_draft_cb(compose, 0, NULL);
1345 compose_insert_file_cb(compose, 0, NULL);
1348 compose_attach_cb(compose, 0, NULL);
1351 compose_insert_sig(compose);
1354 compose_ext_editor_cb(compose, 0, NULL);
1357 compose_wrap_line(compose);
1360 compose_address_cb(compose, 0, NULL);
1367 static void compose_entries_set(Compose *compose, const gchar *mailto)
1372 gchar *subject = NULL;
1375 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1378 compose_entry_append(compose, to, COMPOSE_TO);
1380 compose_entry_append(compose, cc, COMPOSE_CC);
1382 compose_entry_append(compose, bcc, COMPOSE_BCC);
1384 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1386 gtk_stext_insert(GTK_STEXT(compose->text),
1387 NULL, NULL, NULL, body, -1);
1388 gtk_stext_insert(GTK_STEXT(compose->text),
1389 NULL, NULL, NULL, "\n", 1);
1399 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1401 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1402 {"Cc:", NULL, FALSE},
1403 {"References:", NULL, FALSE},
1404 {"Bcc:", NULL, FALSE},
1405 {"Newsgroups:", NULL, FALSE},
1406 {"Followup-To:", NULL, FALSE},
1407 {"List-Post:", NULL, FALSE},
1408 {"X-Priority:", NULL, FALSE},
1409 {NULL, NULL, FALSE}};
1425 g_return_val_if_fail(msginfo != NULL, -1);
1427 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1428 procheader_get_header_fields(fp, hentry);
1431 if (hentry[H_REPLY_TO].body != NULL) {
1432 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1433 compose->replyto = hentry[H_REPLY_TO].body;
1434 hentry[H_REPLY_TO].body = NULL;
1436 if (hentry[H_CC].body != NULL) {
1437 conv_unmime_header_overwrite(hentry[H_CC].body);
1438 compose->cc = hentry[H_CC].body;
1439 hentry[H_CC].body = NULL;
1441 if (hentry[H_REFERENCES].body != NULL) {
1442 if (compose->mode == COMPOSE_REEDIT)
1443 compose->references = hentry[H_REFERENCES].body;
1445 compose->references = compose_parse_references
1446 (hentry[H_REFERENCES].body, msginfo->msgid);
1447 g_free(hentry[H_REFERENCES].body);
1449 hentry[H_REFERENCES].body = NULL;
1451 if (hentry[H_BCC].body != NULL) {
1452 if (compose->mode == COMPOSE_REEDIT) {
1453 conv_unmime_header_overwrite(hentry[H_BCC].body);
1454 compose->bcc = hentry[H_BCC].body;
1456 g_free(hentry[H_BCC].body);
1457 hentry[H_BCC].body = NULL;
1459 if (hentry[H_NEWSGROUPS].body != NULL) {
1460 conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
1461 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1462 hentry[H_NEWSGROUPS].body = NULL;
1464 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1465 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1466 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1467 hentry[H_FOLLOWUP_TO].body = NULL;
1469 if (hentry[H_LIST_POST].body != NULL) {
1472 extract_address(hentry[H_LIST_POST].body);
1473 if (hentry[H_LIST_POST].body[0] != '\0') {
1474 scan_mailto_url(hentry[H_LIST_POST].body,
1475 &to, NULL, NULL, NULL, NULL);
1477 g_free(compose->ml_post);
1478 compose->ml_post = to;
1481 g_free(hentry[H_LIST_POST].body);
1482 hentry[H_LIST_POST].body = NULL;
1485 /* CLAWS - X-Priority */
1486 if (compose->mode == COMPOSE_REEDIT)
1487 if (hentry[H_X_PRIORITY].body != NULL) {
1490 priority = atoi(hentry[H_X_PRIORITY].body);
1491 g_free(hentry[H_X_PRIORITY].body);
1493 hentry[H_X_PRIORITY].body = NULL;
1495 if (priority < PRIORITY_HIGHEST ||
1496 priority > PRIORITY_LOWEST)
1497 priority = PRIORITY_NORMAL;
1499 compose->priority = priority;
1502 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1503 compose->inreplyto = g_strdup(msginfo->inreplyto);
1504 else if (compose->mode != COMPOSE_REEDIT &&
1505 msginfo->msgid && *msginfo->msgid) {
1506 compose->inreplyto = g_strdup(msginfo->msgid);
1508 if (!compose->references) {
1509 if (msginfo->inreplyto && *msginfo->inreplyto)
1510 compose->references =
1511 g_strdup_printf("<%s>\n\t<%s>",
1515 compose->references =
1516 g_strconcat("<", msginfo->msgid, ">",
1524 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1526 GSList *ref_id_list, *cur;
1530 ref_id_list = references_list_append(NULL, ref);
1531 if (!ref_id_list) return NULL;
1532 if (msgid && *msgid)
1533 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1538 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1539 /* "<" + Message-ID + ">" + CR+LF+TAB */
1540 len += strlen((gchar *)cur->data) + 5;
1542 if (len > MAX_REFERENCES_LEN) {
1543 /* remove second message-ID */
1544 if (ref_id_list && ref_id_list->next &&
1545 ref_id_list->next->next) {
1546 g_free(ref_id_list->next->data);
1547 ref_id_list = g_slist_remove
1548 (ref_id_list, ref_id_list->next->data);
1550 slist_free_strings(ref_id_list);
1551 g_slist_free(ref_id_list);
1558 new_ref = g_string_new("");
1559 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1560 if (new_ref->len > 0)
1561 g_string_append(new_ref, "\n\t");
1562 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1565 slist_free_strings(ref_id_list);
1566 g_slist_free(ref_id_list);
1568 new_ref_str = new_ref->str;
1569 g_string_free(new_ref, FALSE);
1574 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1575 const gchar *fmt, const gchar *qmark,
1578 GtkSText *text = GTK_STEXT(compose->text);
1579 static MsgInfo dummyinfo;
1580 gchar *quote_str = NULL;
1586 msginfo = &dummyinfo;
1588 if (qmark != NULL) {
1589 quote_fmt_init(msginfo, NULL, NULL);
1590 quote_fmt_scan_string(qmark);
1593 buf = quote_fmt_get_buffer();
1595 alertpanel_error(_("Quote mark format error."));
1597 Xstrdup_a(quote_str, buf, return NULL)
1600 if (fmt && *fmt != '\0') {
1601 quote_fmt_init(msginfo, quote_str, body);
1602 quote_fmt_scan_string(fmt);
1605 buf = quote_fmt_get_buffer();
1607 alertpanel_error(_("Message reply/forward format error."));
1613 gtk_stext_freeze(text);
1615 for (p = buf; *p != '\0'; ) {
1616 lastp = strchr(p, '\n');
1617 len = lastp ? lastp - p + 1 : -1;
1618 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1625 gtk_stext_thaw(text);
1630 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1631 gboolean to_all, gboolean to_ml,
1633 gboolean followup_and_reply_to)
1635 GSList *cc_list = NULL;
1638 gchar *replyto = NULL;
1639 GHashTable *to_table;
1641 g_return_if_fail(compose->account != NULL);
1642 g_return_if_fail(msginfo != NULL);
1644 if (compose->account->protocol != A_NNTP) {
1645 if (!compose->replyto && to_ml && compose->ml_post
1646 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1647 compose_entry_append(compose,
1650 else if (!(to_all || to_sender)
1652 && msginfo->folder->prefs->enable_default_reply_to) {
1653 compose_entry_append(compose,
1654 msginfo->folder->prefs->default_reply_to,
1657 compose_entry_append(compose,
1658 (compose->replyto && !to_sender)
1659 ? compose->replyto :
1660 msginfo->from ? msginfo->from : "",
1663 if (to_sender || (compose->followup_to &&
1664 !strncmp(compose->followup_to, "poster", 6)))
1665 compose_entry_append
1667 ((compose->replyto && !to_sender)
1668 ? compose->replyto :
1669 msginfo->from ? msginfo->from : ""),
1672 else if (followup_and_reply_to || to_all) {
1673 compose_entry_append
1675 (compose->replyto ? compose->replyto :
1676 msginfo->from ? msginfo->from : ""),
1679 compose_entry_append
1681 compose->followup_to ? compose->followup_to :
1682 compose->newsgroups ? compose->newsgroups : "",
1683 COMPOSE_NEWSGROUPS);
1685 else if (compose->replyto)
1686 compose_entry_append
1687 (compose,compose->replyto,
1690 compose_entry_append
1692 compose->followup_to ? compose->followup_to :
1693 compose->newsgroups ? compose->newsgroups : "",
1694 COMPOSE_NEWSGROUPS);
1697 if (msginfo->subject && *msginfo->subject) {
1698 gchar *buf, *buf2, *p;
1700 buf = g_strdup(msginfo->subject);
1701 while (!strncasecmp(buf, "Re:", 3)) {
1703 while (isspace(*p)) p++;
1704 memmove(buf, p, strlen(p) + 1);
1707 buf2 = g_strdup_printf("Re: %s", buf);
1708 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1712 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1714 if (to_ml && compose->ml_post) return;
1715 if (!to_all || compose->account->protocol == A_NNTP) return;
1717 if (compose->replyto) {
1718 Xstrdup_a(replyto, compose->replyto, return);
1719 extract_address(replyto);
1721 if (msginfo->from) {
1722 Xstrdup_a(from, msginfo->from, return);
1723 extract_address(from);
1726 if (replyto && from)
1727 cc_list = address_list_append(cc_list, from);
1728 cc_list = address_list_append(cc_list, msginfo->to);
1729 cc_list = address_list_append(cc_list, compose->cc);
1731 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1733 g_hash_table_insert(to_table, replyto, GINT_TO_POINTER(1));
1734 if (compose->account)
1735 g_hash_table_insert(to_table, compose->account->address,
1736 GINT_TO_POINTER(1));
1738 /* remove address on To: and that of current account */
1739 for (cur = cc_list; cur != NULL; ) {
1740 GSList *next = cur->next;
1742 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1743 cc_list = g_slist_remove(cc_list, cur->data);
1745 g_hash_table_insert(to_table, cur->data, cur);
1749 g_hash_table_destroy(to_table);
1752 for (cur = cc_list; cur != NULL; cur = cur->next)
1753 compose_entry_append(compose, (gchar *)cur->data,
1755 slist_free_strings(cc_list);
1756 g_slist_free(cc_list);
1760 #define SET_ENTRY(entry, str) \
1763 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1766 #define SET_ADDRESS(type, str) \
1769 compose_entry_append(compose, str, type); \
1772 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1774 g_return_if_fail(msginfo != NULL);
1776 SET_ENTRY(subject_entry, msginfo->subject);
1777 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1778 SET_ADDRESS(COMPOSE_CC, compose->cc);
1779 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1780 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1781 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
1782 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
1784 compose_update_priority_menu_item(compose);
1786 compose_update_gnupg_mode_menu_item(compose);
1788 compose_show_first_last_header(compose, TRUE);
1795 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1799 size_t buf_len = 128;
1801 if (strlen(sigfile) < 2)
1804 sigprg = popen(sigfile+1, "r");
1807 buf = g_malloc(buf_len);
1810 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1811 "Unable to insert signature (malloc failed)\n", -1);
1817 while (!feof(sigprg)) {
1818 bzero(buf, buf_len);
1819 fread(buf, buf_len-1, 1, sigprg);
1820 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1828 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1829 "Can't exec file: ", -1);
1830 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1835 static void compose_insert_sig(Compose *compose)
1839 if (compose->account && compose->account->sig_path)
1840 sigfile = g_strdup(compose->account->sig_path);
1842 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1843 DEFAULT_SIGNATURE, NULL);
1845 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1850 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1851 if (compose->account->sig_sep) {
1852 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1853 compose->account->sig_sep, -1);
1854 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1858 if (sigfile[0] == '|')
1859 compose_exec_sig(compose, sigfile);
1861 compose_insert_file(compose, sigfile);
1865 static void compose_insert_file(Compose *compose, const gchar *file)
1867 GtkSText *text = GTK_STEXT(compose->text);
1868 gchar buf[BUFFSIZE];
1872 g_return_if_fail(file != NULL);
1874 if ((fp = fopen(file, "rb")) == NULL) {
1875 FILE_OP_ERROR(file, "fopen");
1879 gtk_stext_freeze(text);
1881 while (fgets(buf, sizeof(buf), fp) != NULL) {
1882 /* strip <CR> if DOS/Windows file,
1883 replace <CR> with <LF> if Macintosh file. */
1886 if (len > 0 && buf[len - 1] != '\n') {
1888 if (buf[len] == '\r') buf[len] = '\n';
1890 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1893 gtk_stext_thaw(text);
1898 static void compose_attach_append(Compose *compose, const gchar *file,
1899 const gchar *filename,
1900 const gchar *content_type)
1903 gchar *text[N_ATTACH_COLS];
1908 if (!is_file_exist(file)) {
1909 g_warning("File %s doesn't exist\n", file);
1912 if ((size = get_file_size(file)) < 0) {
1913 g_warning("Can't get file size of %s\n", file);
1917 alertpanel_notice(_("File %s is empty."), file);
1920 if ((fp = fopen(file, "rb")) == NULL) {
1921 alertpanel_error(_("Can't read %s."), file);
1926 #if 0 /* NEW COMPOSE GUI */
1927 if (!compose->use_attach) {
1928 GtkItemFactory *ifactory;
1929 GtkWidget *menuitem;
1931 ifactory = gtk_item_factory_from_widget(compose->menubar);
1932 menuitem = gtk_item_factory_get_item(ifactory,
1933 "/View/Attachment");
1934 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1938 ainfo = g_new0(AttachInfo, 1);
1939 ainfo->file = g_strdup(file);
1942 ainfo->content_type = g_strdup(content_type);
1943 if (!strcasecmp(content_type, "message/rfc822")) {
1944 if (procmime_get_encoding_for_file(file) == ENC_7BIT)
1945 ainfo->encoding = ENC_7BIT;
1947 ainfo->encoding = ENC_8BIT;
1948 ainfo->name = g_strdup_printf
1950 g_basename(filename ? filename : file));
1952 if (!g_strncasecmp(content_type, "text", 4))
1954 procmime_get_encoding_for_file(file);
1956 ainfo->encoding = ENC_BASE64;
1957 ainfo->name = g_strdup
1958 (g_basename(filename ? filename : file));
1961 ainfo->content_type = procmime_get_mime_type(file);
1962 if (!ainfo->content_type) {
1963 ainfo->content_type =
1964 g_strdup("application/octet-stream");
1965 ainfo->encoding = ENC_BASE64;
1966 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
1967 ainfo->encoding = procmime_get_encoding_for_file(file);
1969 ainfo->encoding = ENC_BASE64;
1970 ainfo->name = g_strdup(g_basename(filename ? filename : file));
1974 text[COL_MIMETYPE] = ainfo->content_type;
1975 text[COL_SIZE] = to_human_readable(size);
1976 text[COL_NAME] = ainfo->name;
1978 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1979 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1982 #define IS_FIRST_PART_TEXT(info) \
1983 ((info->mime_type == MIME_TEXT || info->mime_type == MIME_TEXT_HTML || \
1984 info->mime_type == MIME_TEXT_ENRICHED) || \
1985 (info->mime_type == MIME_MULTIPART && info->content_type && \
1986 !strcasecmp(info->content_type, "multipart/alternative") && \
1987 (info->children && \
1988 (info->children->mime_type == MIME_TEXT || \
1989 info->children->mime_type == MIME_TEXT_HTML || \
1990 info->children->mime_type == MIME_TEXT_ENRICHED))))
1992 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
1999 mimeinfo = procmime_scan_message(msginfo);
2000 if (!mimeinfo) return;
2002 /* skip first text (presumably message body) */
2003 child = mimeinfo->children;
2004 if (!child || IS_FIRST_PART_TEXT(mimeinfo)) {
2005 procmime_mimeinfo_free_all(mimeinfo);
2009 if (IS_FIRST_PART_TEXT(child))
2010 child = child->next;
2012 infile = procmsg_get_message_file_path(msginfo);
2014 while (child != NULL) {
2015 if (child->children || child->mime_type == MIME_MULTIPART) {
2016 child = procmime_mimeinfo_next(child);
2019 if(child->parent && child->parent->parent
2020 && !strcasecmp(child->parent->parent->content_type, "multipart/signed")
2021 && child->mime_type == MIME_TEXT) {
2022 /* this is the main text part of a signed message */
2023 child = procmime_mimeinfo_next(child);
2026 outfile = procmime_get_tmp_file_name(child);
2027 if (procmime_get_part(outfile, infile, child) < 0)
2028 g_warning("Can't get the part of multipart message.");
2029 else if (compose->mode != COMPOSE_REEDIT || strcmp(child->content_type, "application/pgp-signature"))
2030 compose_attach_append
2032 child->filename ? child->filename : child->name,
2033 child->content_type);
2035 child = child->next;
2039 procmime_mimeinfo_free_all(mimeinfo);
2042 #undef IS_FIRST_PART_TEXT
2044 #define GET_CHAR(pos, buf, len) \
2046 if (text->use_wchar) \
2047 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2049 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2054 #define INDENT_CHARS ">|#"
2055 #define SPACE_CHARS " \t"
2057 static void compose_wrap_line(Compose *compose)
2059 GtkSText *text = GTK_STEXT(compose->text);
2060 gint ch_len, last_ch_len;
2061 gchar cbuf[MB_LEN_MAX], last_ch;
2065 gint p_start, p_end;
2066 gint line_pos, cur_pos;
2067 gint line_len, cur_len;
2069 gtk_stext_freeze(text);
2071 text_len = gtk_stext_get_length(text);
2073 /* check to see if the point is on the paragraph mark (empty line). */
2074 cur_pos = gtk_stext_get_point(text);
2075 GET_CHAR(cur_pos, cbuf, ch_len);
2076 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2078 goto compose_end; /* on the paragraph mark */
2079 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2080 if (ch_len == 1 && *cbuf == '\n')
2081 goto compose_end; /* on the paragraph mark */
2084 /* find paragraph start. */
2085 line_end = quoted = 0;
2086 for (p_start = cur_pos; p_start >= 0; --p_start) {
2087 GET_CHAR(p_start, cbuf, ch_len);
2088 if (ch_len == 1 && *cbuf == '\n') {
2090 goto compose_end; /* quoted part */
2098 && strchr(prefs_common.quote_chars, *cbuf))
2100 else if (ch_len != 1 || !isspace(*cbuf))
2109 /* find paragraph end. */
2111 for (p_end = cur_pos; p_end < text_len; p_end++) {
2112 GET_CHAR(p_end, cbuf, ch_len);
2113 if (ch_len == 1 && *cbuf == '\n') {
2120 if (line_end && ch_len == 1 &&
2121 strchr(prefs_common.quote_chars, *cbuf))
2122 goto compose_end; /* quoted part */
2127 if (p_end >= text_len)
2130 if (p_start >= p_end)
2133 line_len = cur_len = 0;
2137 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2140 GET_CHAR(cur_pos, cbuf, ch_len);
2147 if (ch_len == 1 && isspace(*cbuf))
2150 if (ch_len == 1 && *cbuf == '\n') {
2152 if (last_ch_len == 1 && !isspace(last_ch)) {
2153 if (cur_pos + 1 < p_end) {
2154 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2155 if (ch_len == 1 && !isspace(*cbuf))
2159 gtk_stext_set_point(text, cur_pos + 1);
2160 gtk_stext_backward_delete(text, 1);
2162 gtk_stext_set_point(text, cur_pos);
2163 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2173 last_ch_len = ch_len;
2177 line_pos = cur_pos + 1;
2178 line_len = cur_len + ch_len;
2181 if (cur_len + ch_len > prefs_common.linewrap_len &&
2185 GET_CHAR(line_pos - 1, cbuf, ch_len);
2186 if (ch_len == 1 && isspace(*cbuf)) {
2187 gtk_stext_set_point(text, line_pos);
2188 gtk_stext_backward_delete(text, 1);
2197 gtk_stext_set_point(text, line_pos);
2198 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2202 cur_len = cur_len - line_len + ch_len;
2208 line_pos = cur_pos + 1;
2209 line_len = cur_len + ch_len;
2215 gtk_stext_thaw(text);
2220 /* Darko: used when I debug wrapping */
2221 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2224 gchar cbuf[MB_LEN_MAX];
2226 printf("%d [", pos);
2227 for (i = pos; i < tlen; i++) {
2228 GET_CHAR(i, cbuf, clen);
2229 if (clen < 0) break;
2230 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2232 fwrite(cbuf, clen, 1, stdout);
2240 WAIT_FOR_INDENT_CHAR,
2241 WAIT_FOR_INDENT_CHAR_OR_SPACE
2244 /* return indent length, we allow:
2245 > followed by spaces/tabs
2246 | followed by spaces/tabs
2247 uppercase characters immediately followed by >,
2248 and the repeating sequences of the above */
2249 /* return indent length */
2250 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2253 guint i, ch_len, alnum_cnt = 0;
2254 IndentState state = WAIT_FOR_INDENT_CHAR;
2255 gchar cbuf[MB_LEN_MAX];
2259 for (i = start_pos; i < text_len; i++) {
2260 GET_CHAR(i, cbuf, ch_len);
2264 if (cbuf[0] == '\n')
2267 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2268 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2271 case WAIT_FOR_SPACE:
2272 if (is_space == FALSE)
2274 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2276 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2277 if (is_indent == FALSE && is_space == FALSE &&
2280 if (is_space == TRUE) {
2282 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2283 } else if (is_indent == TRUE) {
2285 state = WAIT_FOR_SPACE;
2288 state = WAIT_FOR_INDENT_CHAR;
2291 case WAIT_FOR_INDENT_CHAR:
2292 if (is_indent == FALSE && !isupper(cbuf[0]))
2294 if (is_indent == TRUE) {
2296 && !strchr(prefs_common.quote_chars, cbuf[0]))
2299 state = WAIT_FOR_SPACE;
2310 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2316 /* insert quotation string when line was wrapped */
2317 static guint ins_quote(GtkSText *text, guint indent_len,
2318 guint prev_line_pos, guint text_len,
2321 guint i, ins_len = 0;
2325 for (i = 0; i < indent_len; i++) {
2326 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2327 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2329 ins_len = indent_len;
2335 /* check if we should join the next line */
2336 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2337 guint prev_ilen, gboolean autowrap)
2339 guint indent_len, ch_len;
2340 gboolean do_join = FALSE;
2341 gchar cbuf[MB_LEN_MAX];
2343 indent_len = get_indent_length(text, start_pos, tlen);
2345 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2346 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2347 if (ch_len > 0 && (cbuf[0] != '\n'))
2354 static void compose_wrap_line_all(Compose *compose)
2356 compose_wrap_line_all_full(compose, FALSE);
2359 #define STEXT_FREEZE() \
2360 if (!frozen) { gtk_stext_freeze(text); frozen = TRUE; }
2362 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2364 GtkSText *text = GTK_STEXT(compose->text);
2366 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2367 gint line_len = 0, cur_len = 0;
2369 gboolean is_new_line = TRUE, do_delete = FALSE;
2371 gboolean linewrap_quote = TRUE;
2372 gboolean set_editable_pos = FALSE;
2373 gint editable_pos = 0;
2374 gboolean frozen = FALSE;
2375 guint linewrap_len = prefs_common.linewrap_len;
2376 gchar *qfmt = prefs_common.quotemark;
2377 gchar cbuf[MB_LEN_MAX];
2379 tlen = gtk_stext_get_length(text);
2381 for (; cur_pos < tlen; cur_pos++) {
2382 /* mark position of new line - needed for quotation wrap */
2385 i_len = get_indent_length(text, cur_pos, tlen);
2387 is_new_line = FALSE;
2390 g_print("new line i_len=%d p_pos=", i_len);
2391 dump_text(text, p_pos, tlen, 1);
2395 GET_CHAR(cur_pos, cbuf, ch_len);
2397 /* fix line length for tabs */
2398 if (ch_len == 1 && *cbuf == '\t') {
2399 guint tab_width = text->default_tab_width;
2400 guint tab_offset = line_len % tab_width;
2403 g_print("found tab at pos=%d line_len=%d ", cur_pos,
2407 line_len += tab_width - tab_offset - 1;
2411 printf("new_len=%d\n", line_len);
2415 /* we have encountered line break */
2416 if (ch_len == 1 && *cbuf == '\n') {
2418 gchar cb[MB_LEN_MAX];
2420 /* should we join the next line */
2421 if ((autowrap || i_len != cur_len) && do_delete &&
2423 (text, cur_pos + 1, tlen, i_len, autowrap))
2429 g_print("found CR at %d do_del is %d next line is ",
2430 cur_pos, do_delete);
2431 dump_text(text, cur_pos + 1, tlen, 1);
2434 /* skip delete if it is continuous URL */
2435 if (do_delete && (line_pos - p_pos <= i_len) &&
2436 gtk_stext_is_uri_string(text, line_pos, tlen))
2440 g_print("l_len=%d wrap_len=%d do_del=%d\n",
2441 line_len, linewrap_len, do_delete);
2443 /* should we delete to perform smart wrapping */
2444 if (line_len < linewrap_len && do_delete) {
2446 /* get rid of newline */
2447 gtk_stext_set_point(text, cur_pos);
2448 gtk_stext_forward_delete(text, 1);
2451 /* if text starts with quote fmt or with
2452 indent string, delete them */
2455 ilen = gtk_stext_str_compare_n
2456 (text, cur_pos, p_pos, i_len,
2459 gtk_stext_forward_delete
2465 GET_CHAR(cur_pos, cb, clen);
2467 /* insert space if it's alphanumeric */
2468 if ((cur_pos != line_pos) &&
2469 ((clen > 1) || isalnum(cb[0]))) {
2470 gtk_stext_insert(text, NULL, NULL,
2475 /* and start over with current line */
2476 cur_pos = p_pos - 1;
2478 line_len = cur_len = 0;
2482 g_print("after delete l_pos=");
2483 dump_text(text, line_pos, tlen, 1);
2488 /* mark new line beginning */
2489 line_pos = cur_pos + 1;
2490 line_len = cur_len = 0;
2501 /* possible line break */
2502 if (ch_len == 1 && isspace(*cbuf)) {
2503 line_pos = cur_pos + 1;
2504 line_len = cur_len + ch_len;
2507 /* are we over wrapping length set in preferences ? */
2508 if (cur_len + ch_len > linewrap_len) {
2512 g_print("should wrap cur_pos=%d ", cur_pos);
2513 dump_text(text, p_pos, tlen, 1);
2514 dump_text(text, line_pos, tlen, 1);
2516 /* force wrapping if it is one long word but not URL */
2517 if (line_pos - p_pos <= i_len)
2518 if (!gtk_stext_is_uri_string
2519 (text, line_pos, tlen))
2520 line_pos = cur_pos - 1;
2522 g_print("new line_pos=%d\n", line_pos);
2525 GET_CHAR(line_pos - 1, cbuf, clen);
2527 /* if next character is space delete it */
2528 if (clen == 1 && isspace(*cbuf)) {
2529 if (p_pos + i_len != line_pos ||
2530 !gtk_stext_is_uri_string
2531 (text, line_pos, tlen)) {
2533 /* workaround for correct cursor
2535 if (set_editable_pos == FALSE) {
2536 editable_pos = gtk_editable_get_position(GTK_EDITABLE(text));
2537 if (editable_pos == line_pos)
2538 set_editable_pos = TRUE;
2540 gtk_stext_set_point(text, line_pos);
2541 gtk_stext_backward_delete(text, 1);
2550 /* if it is URL at beginning of line don't wrap */
2551 if (p_pos + i_len == line_pos &&
2552 gtk_stext_is_uri_string(text, line_pos, tlen)) {
2554 g_print("found URL at ");
2555 dump_text(text, line_pos, tlen, 1);
2562 gtk_stext_set_point(text, line_pos);
2563 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2564 /* gtk_stext_compact_buffer(text); */
2567 /* for loop will increase it */
2568 cur_pos = line_pos - 1;
2569 /* start over with current line */
2571 line_len = cur_len = 0;
2572 if (autowrap || i_len > 0)
2577 g_print("after CR insert ");
2578 dump_text(text, line_pos, tlen, 1);
2579 dump_text(text, cur_pos, tlen, 1);
2582 /* should we insert quotation ? */
2583 if (linewrap_quote && i_len) {
2584 /* only if line is not already quoted */
2585 if (!gtk_stext_str_compare
2586 (text, line_pos, tlen, qfmt)) {
2589 if (line_pos - p_pos > i_len) {
2591 (text, i_len, p_pos,
2596 g_print("after quote insert ");
2597 dump_text(text, line_pos, tlen, 1);
2605 line_pos = cur_pos + 1;
2606 line_len = cur_len + ch_len;
2608 /* advance to next character in buffer */
2613 gtk_stext_thaw(text);
2615 if (set_editable_pos && editable_pos <= tlen)
2616 gtk_editable_set_position(GTK_EDITABLE(text), editable_pos);
2622 static void compose_set_title(Compose *compose)
2627 edited = compose->modified ? _(" [Edited]") : "";
2628 if (compose->account && compose->account->address)
2629 str = g_strdup_printf(_("%s - Compose message%s"),
2630 compose->account->address, edited);
2632 str = g_strdup_printf(_("Compose message%s"), edited);
2633 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2638 * compose_current_mail_account:
2640 * Find a current mail account (the currently selected account, or the
2641 * default account, if a news account is currently selected). If a
2642 * mail account cannot be found, display an error message.
2644 * Return value: Mail account, or NULL if not found.
2646 static PrefsAccount *
2647 compose_current_mail_account(void)
2651 if (cur_account && cur_account->protocol != A_NNTP)
2654 ac = account_get_default();
2655 if (!ac || ac->protocol == A_NNTP) {
2656 alertpanel_error(_("Account for sending mail is not specified.\n"
2657 "Please select a mail account before sending."));
2664 static void compose_select_account(Compose *compose, PrefsAccount *account)
2666 GtkWidget *menuitem;
2667 GtkItemFactory *ifactory;
2669 g_return_if_fail(account != NULL);
2671 compose->account = account;
2673 compose_set_title(compose);
2675 ifactory = gtk_item_factory_from_widget(compose->menubar);
2677 if (account->protocol == A_NNTP) {
2678 gtk_widget_show(compose->newsgroups_hbox);
2679 gtk_widget_show(compose->newsgroups_entry);
2680 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
2681 compose->use_newsgroups = TRUE;
2683 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2684 gtk_check_menu_item_set_active
2685 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2686 gtk_widget_set_sensitive(menuitem, TRUE);
2687 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2688 gtk_check_menu_item_set_active
2689 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2690 gtk_widget_set_sensitive(menuitem, TRUE);
2692 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
2694 gtk_widget_hide(compose->newsgroups_hbox);
2695 gtk_widget_hide(compose->newsgroups_entry);
2696 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
2697 gtk_widget_queue_resize(compose->table_vbox);
2698 compose->use_newsgroups = FALSE;
2700 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2701 gtk_check_menu_item_set_active
2702 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2703 gtk_widget_set_sensitive(menuitem, FALSE);
2704 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2705 gtk_check_menu_item_set_active
2706 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2707 gtk_widget_set_sensitive(menuitem, FALSE);
2709 menuitem = gtk_item_factory_get_item(ifactory, "/View/Followup to");
2710 gtk_check_menu_item_set_active
2711 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2712 gtk_widget_set_sensitive(menuitem, FALSE);
2715 if (account->set_autocc) {
2716 compose_entry_show(compose, COMPOSE_ENTRY_CC);
2717 if (account->auto_cc && compose->mode != COMPOSE_REEDIT)
2718 compose_entry_set(compose, account->auto_cc,
2721 if (account->set_autobcc) {
2722 compose_entry_show(compose, COMPOSE_ENTRY_BCC);
2723 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
2724 compose_entry_set(compose, account->auto_bcc,
2727 if (account->set_autoreplyto) {
2728 compose_entry_show(compose, COMPOSE_ENTRY_REPLY_TO);
2729 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
2730 compose_entry_set(compose, account->auto_replyto,
2731 COMPOSE_ENTRY_REPLY_TO);
2734 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
2735 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2736 prefs_common.show_ruler);
2740 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
2741 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2742 account->default_sign);
2743 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
2744 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2745 account->default_encrypt);
2747 activate_gnupg_mode(compose, account);
2748 #endif /* USE_GPGME */
2751 gboolean compose_check_for_valid_recipient(Compose *compose) {
2752 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2753 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2754 gboolean recipient_found = FALSE;
2758 /* free to and newsgroup list */
2759 slist_free_strings(compose->to_list);
2760 g_slist_free(compose->to_list);
2761 compose->to_list = NULL;
2763 slist_free_strings(compose->newsgroup_list);
2764 g_slist_free(compose->newsgroup_list);
2765 compose->newsgroup_list = NULL;
2767 /* search header entries for to and newsgroup entries */
2768 for (list = compose->header_list; list; list = list->next) {
2771 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
2772 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2774 if (entry[0] != '\0') {
2775 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2776 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2777 compose->to_list = address_list_append(compose->to_list, entry);
2778 recipient_found = TRUE;
2781 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2782 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2783 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2784 recipient_found = TRUE;
2791 return recipient_found;
2794 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
2798 if (compose_check_for_valid_recipient(compose) == FALSE) {
2799 alertpanel_error(_("Recipient is not specified."));
2803 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2804 if (*str == '\0' && check_subject == TRUE) {
2807 aval = alertpanel(_("Send"),
2808 _("Subject is empty. Send it anyway?"),
2809 _("Yes"), _("No"), NULL);
2810 if (aval != G_ALERTDEFAULT)
2817 gint compose_send(Compose *compose)
2824 if (compose_check_entries(compose, TRUE) == FALSE)
2827 val = compose_queue(compose, &msgnum, &folder);
2829 alertpanel_error(_("Could not queue message for sending"));
2834 alertpanel_error(_("The message was queued but could not be sent.\nUse \"Send queued messages\" from the main window to retry."));
2838 msgpath = folder_item_fetch_msg(folder, msgnum);
2839 val = procmsg_send_message_queue(msgpath);
2842 folder_item_remove_msg(folder, msgnum);
2847 #if 0 /* compose restructure */
2848 gint compose_send(Compose *compose)
2850 gchar tmp[MAXPATHLEN + 1];
2852 static gboolean lock = FALSE;
2856 g_return_val_if_fail(compose->account != NULL, -1);
2860 if (compose_check_entries(compose, TRUE) == FALSE) {
2865 /* write to temporary file */
2866 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
2867 get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
2869 if (prefs_common.linewrap_at_send)
2870 compose_wrap_line_all(compose);
2872 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2877 if (!compose->to_list && !compose->newsgroup_list) {
2878 g_warning("can't get recipient list.");
2884 if (compose->to_list) {
2887 #if 0 /* NEW COMPOSE GUI */
2888 if (compose->account->protocol != A_NNTP)
2889 ac = compose->account;
2891 ac = account_find_from_address(compose->account->address);
2893 if (cur_account && cur_account->protocol != A_NNTP)
2896 ac = account_get_default();
2898 if (!ac || ac->protocol == A_NNTP) {
2899 alertpanel_error(_("Account for sending mail is not specified.\n"
2900 "Please select a mail account before sending."));
2907 ac = compose->account;
2909 ok = send_message(tmp, ac, compose->to_list);
2912 if (ok == 0 && compose->newsgroup_list) {
2913 ok = news_post(FOLDER(compose->account->folder), tmp);
2915 alertpanel_error(_("Error occurred while posting the message to %s ."),
2916 compose->account->nntp_server);
2923 /* queue message if failed to send */
2925 if (prefs_common.queue_msg) {
2930 _("Error occurred while sending the message.\n"
2931 "Put this message into queue folder?"),
2932 _("OK"), _("Cancel"), NULL);
2933 if (G_ALERTDEFAULT == val) {
2934 ok = compose_queue(compose, tmp);
2936 alertpanel_error(_("Can't queue the message."));
2939 alertpanel_error_log(_("Error occurred while sending the message."));
2941 if (compose->mode == COMPOSE_REEDIT) {
2942 compose_remove_reedit_target(compose);
2944 /* save message to outbox */
2945 if (prefs_common.savemsg) {
2948 outbox = account_get_special_folder
2949 (compose->account, F_OUTBOX);
2950 if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
2952 (_("Can't save the message to Sent."));
2962 static gboolean compose_use_attach(Compose *compose) {
2963 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2966 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
2969 gchar buf[BUFFSIZE];
2971 gboolean first_address;
2973 ComposeHeaderEntry *headerentry;
2974 gchar *headerentryname;
2978 debug_print("Writing redirect header\n");
2980 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
2981 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
2983 first_address = TRUE;
2984 for (list = compose->header_list; list; list = list->next) {
2985 headerentry = ((ComposeHeaderEntry *)list->data);
2986 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2988 if (g_strcasecmp(headerentryname, cc_hdr) == 0
2989 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2990 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2991 Xstrdup_a(str, str, return -1);
2993 if (str[0] != '\0') {
2994 compose_convert_header
2995 (buf, sizeof(buf), str,
2996 strlen("Resent-To") + 2);
2997 if (first_address) {
2998 fprintf(fp, "Resent-To: ");
2999 first_address = FALSE;
3003 fprintf(fp, "%s", buf);
3007 /* if (!first_address) { */
3014 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3016 gchar buf[BUFFSIZE];
3018 /* struct utsname utsbuf; */
3020 g_return_val_if_fail(fp != NULL, -1);
3021 g_return_val_if_fail(compose->account != NULL, -1);
3022 g_return_val_if_fail(compose->account->address != NULL, -1);
3025 get_rfc822_date(buf, sizeof(buf));
3026 fprintf(fp, "Resent-Date: %s\n", buf);
3029 if (compose->account->name && *compose->account->name) {
3030 compose_convert_header
3031 (buf, sizeof(buf), compose->account->name,
3033 fprintf(fp, "Resent-From: %s <%s>\n",
3034 buf, compose->account->address);
3036 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3039 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3041 Xstrdup_a(str, str, return -1);
3044 compose_convert_header(buf, sizeof(buf), str,
3045 strlen("Subject: "));
3046 fprintf(fp, "Subject: %s\n", buf);
3050 /* Resent-Message-ID */
3051 if (compose->account->gen_msgid) {
3052 compose_generate_msgid(compose, buf, sizeof(buf));
3053 fprintf(fp, "Resent-Message-Id: <%s>\n", buf);
3054 compose->msgid = g_strdup(buf);
3057 compose_redirect_write_headers_from_headerlist(compose, fp);
3059 /* separator between header and body */
3065 static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
3070 gchar buf[BUFFSIZE];
3072 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
3073 FILE_OP_ERROR(file, "fopen");
3077 if ((fdest = fopen(file, "wb")) == NULL) {
3078 FILE_OP_ERROR(file, "fopen");
3083 /* chmod for security */
3084 if (change_file_mode_rw(fdest, file) < 0) {
3085 FILE_OP_ERROR(file, "chmod");
3086 g_warning("can't change file mode\n");
3089 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
3090 /* should filter returnpath, delivered-to */
3091 if (g_strncasecmp(buf, "Return-Path:",
3092 strlen("Return-Path:")) == 0 ||
3093 g_strncasecmp(buf, "Delivered-To:",
3094 strlen("Delivered-To:")) == 0 ||
3095 g_strncasecmp(buf, "Received:",
3096 strlen("Received:")) == 0 ||
3097 g_strncasecmp(buf, "Subject:",
3098 strlen("Subject:")) == 0 ||
3099 g_strncasecmp(buf, "X-UIDL:",
3100 strlen("X-UIDL:")) == 0)
3103 if (fputs(buf, fdest) == -1)
3106 if (!prefs_common.redirect_keep_from) {
3107 if (g_strncasecmp(buf, "From:",
3108 strlen("From:")) == 0) {
3109 fputs(" (by way of ", fdest);
3110 if (compose->account->name
3111 && *compose->account->name) {
3112 compose_convert_header
3114 compose->account->name,
3116 fprintf(fdest, "%s <%s>",
3118 compose->account->address);
3120 fprintf(fdest, "%s",
3121 compose->account->address);
3126 if (fputs("\n", fdest) == -1)
3130 compose_redirect_write_headers(compose, fdest);
3132 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3133 if (fwrite(buf, sizeof(gchar), len, fdest) != len) {
3134 FILE_OP_ERROR(file, "fwrite");
3140 if (fclose(fdest) == EOF) {
3141 FILE_OP_ERROR(file, "fclose");
3157 /* interfaces to rfc2015 to keep out the prefs stuff there.
3158 * returns 0 on success and -1 on error. */
3159 static gint compose_create_signers_list(Compose *compose, GSList **pkey_list)
3161 const gchar *key_id = NULL;
3164 switch (compose->account->sign_key) {
3165 case SIGN_KEY_DEFAULT:
3168 case SIGN_KEY_BY_FROM:
3169 key_id = compose->account->address;
3171 case SIGN_KEY_CUSTOM:
3172 key_id = compose->account->sign_key_id;
3178 key_list = rfc2015_create_signers_list(key_id);
3181 alertpanel_error(_("Could not find any key associated with "
3182 "currently selected key id `%s'."), key_id);
3186 *pkey_list = key_list;
3190 /* clearsign message body text */
3191 static gint compose_clearsign_text(Compose *compose, gchar **text)
3196 tmp_file = get_tmp_file();
3197 if (str_write_to_file(*text, tmp_file) < 0) {
3202 if (compose_create_signers_list(compose, &key_list) < 0 ||
3203 rfc2015_clearsign(tmp_file, key_list) < 0) {
3210 *text = file_read_to_str(tmp_file);
3218 #endif /* USE_GPGME */
3220 static gint compose_write_to_file(Compose *compose, const gchar *file,
3228 const gchar *out_codeset;
3229 EncodingType encoding;
3231 if ((fp = fopen(file, "wb")) == NULL) {
3232 FILE_OP_ERROR(file, "fopen");
3236 /* chmod for security */
3237 if (change_file_mode_rw(fp, file) < 0) {
3238 FILE_OP_ERROR(file, "chmod");
3239 g_warning("can't change file mode\n");
3242 /* get all composed text */
3243 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3244 len = strlen(chars);
3245 if (is_ascii_str(chars)) {
3248 out_codeset = CS_US_ASCII;
3249 encoding = ENC_7BIT;
3251 const gchar *src_codeset;
3253 out_codeset = conv_get_outgoing_charset_str();
3254 if (!strcasecmp(out_codeset, CS_US_ASCII))
3255 out_codeset = CS_ISO_8859_1;
3257 if (prefs_common.encoding_method == CTE_BASE64)
3258 encoding = ENC_BASE64;
3259 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
3260 encoding = ENC_QUOTED_PRINTABLE;
3261 else if (prefs_common.encoding_method == CTE_8BIT)
3262 encoding = ENC_8BIT;
3264 encoding = procmime_get_encoding_for_charset(out_codeset);
3268 compose->use_signing && !compose->gnupg_mode &&
3269 encoding == ENC_8BIT)
3270 encoding = ENC_BASE64;
3273 src_codeset = conv_get_current_charset_str();
3274 /* if current encoding is US-ASCII, set it the same as
3275 outgoing one to prevent code conversion failure */
3276 if (!strcasecmp(src_codeset, CS_US_ASCII))
3277 src_codeset = out_codeset;
3279 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3280 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3282 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3287 msg = g_strdup_printf(_("Can't convert the character encoding of the message from\n"
3289 "Send it anyway?"), src_codeset, out_codeset);
3291 (_("Error"), msg, _("Yes"), _("+No"), NULL);
3294 if (aval != G_ALERTDEFAULT) {
3307 canon_buf = canonicalize_str(buf);
3312 if (!is_draft && compose->use_signing && compose->gnupg_mode) {
3313 if (compose_clearsign_text(compose, &buf) < 0) {
3314 g_warning("clearsign failed\n");
3324 if (compose_write_headers
3325 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3326 g_warning("can't write headers\n");
3333 if (compose_use_attach(compose)) {
3335 /* This prolog message is ignored by mime software and
3336 * because it would make our signing/encryption task
3337 * tougher, we don't emit it in that case */
3338 if (!compose->use_signing && !compose->use_encryption)
3340 fputs("This is a multi-part message in MIME format.\n", fp);
3342 fprintf(fp, "\n--%s\n", compose->boundary);
3343 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3345 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3346 procmime_get_encoding_str(encoding));
3352 if (encoding == ENC_BASE64) {
3353 gchar outbuf[B64_BUFFSIZE];
3356 for (i = 0; i < len; i += B64_LINE_SIZE) {
3357 l = MIN(B64_LINE_SIZE, len - i);
3358 base64_encode(outbuf, buf + i, l);
3362 } else if (encoding == ENC_QUOTED_PRINTABLE) {
3366 outbuf = g_malloc(len * 4);
3367 qp_encode_line(outbuf, buf);
3368 outlen = strlen(outbuf);
3369 if (fwrite(outbuf, sizeof(gchar), outlen, fp) != outlen) {
3370 FILE_OP_ERROR(file, "fwrite");
3378 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3379 FILE_OP_ERROR(file, "fwrite");
3387 if (compose_use_attach(compose))
3388 compose_write_attach(compose, fp);
3390 if (fclose(fp) == EOF) {
3391 FILE_OP_ERROR(file, "fclose");
3398 uncanonicalize_file_replace(file);
3402 if ((compose->use_signing && !compose->gnupg_mode) ||
3403 compose->use_encryption) {
3404 if (canonicalize_file_replace(file) < 0) {
3410 if (compose->use_signing && !compose->gnupg_mode) {
3413 if (compose_create_signers_list(compose, &key_list) < 0 ||
3414 rfc2015_sign(file, key_list) < 0) {
3419 if (compose->use_encryption) {
3420 if (rfc2015_encrypt(file, compose->to_list,
3421 compose->gnupg_mode) < 0) {
3426 #endif /* USE_GPGME */
3428 uncanonicalize_file_replace(file);
3433 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3439 if ((fp = fopen(file, "wb")) == NULL) {
3440 FILE_OP_ERROR(file, "fopen");
3444 /* chmod for security */
3445 if (change_file_mode_rw(fp, file) < 0) {
3446 FILE_OP_ERROR(file, "chmod");
3447 g_warning("can't change file mode\n");
3450 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3453 len = strlen(chars);
3454 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3455 FILE_OP_ERROR(file, "fwrite");
3464 if (fclose(fp) == EOF) {
3465 FILE_OP_ERROR(file, "fclose");
3472 static gint compose_remove_reedit_target(Compose *compose)
3475 MsgInfo *msginfo = compose->targetinfo;
3477 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3478 if (!msginfo) return -1;
3480 item = msginfo->folder;
3481 g_return_val_if_fail(item != NULL, -1);
3483 if (procmsg_msg_exist(msginfo) &&
3484 (item->stype == F_DRAFT || item->stype == F_QUEUE
3485 || msginfo == compose->autosaved_draft)) {
3486 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3487 g_warning("can't remove the old message\n");
3495 void compose_remove_draft(Compose *compose)
3498 MsgInfo *msginfo = compose->targetinfo;
3499 drafts = account_get_special_folder(compose->account, F_DRAFT);
3501 if (procmsg_msg_exist(msginfo)) {
3502 folder_item_remove_msg(drafts, msginfo->msgnum);
3507 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3509 return compose_queue_sub (compose, msgnum, item, FALSE);
3511 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3517 gchar buf[BUFFSIZE];
3519 static gboolean lock = FALSE;
3520 PrefsAccount *mailac = NULL, *newsac = NULL;
3522 debug_print("queueing message...\n");
3523 g_return_val_if_fail(compose->account != NULL, -1);
3527 if (compose_check_entries(compose, check_subject) == FALSE) {
3532 if (!compose->to_list && !compose->newsgroup_list) {
3533 g_warning("can't get recipient list.");
3538 if (compose->to_list) {
3539 if (compose->account->protocol != A_NNTP)
3540 mailac = compose->account;
3541 else if (cur_account && cur_account->protocol != A_NNTP)
3542 mailac = cur_account;
3543 else if (!(mailac = compose_current_mail_account())) {
3545 alertpanel_error(_("No account for sending mails available!"));
3550 if (compose->newsgroup_list) {
3551 if (compose->account->protocol == A_NNTP)
3552 newsac = compose->account;
3553 else if (!newsac->protocol != A_NNTP) {
3555 alertpanel_error(_("No account for posting news available!"));
3560 if (prefs_common.linewrap_at_send)
3561 compose_wrap_line_all(compose);
3563 /* write to temporary file */
3564 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3565 G_DIR_SEPARATOR, (gint)compose);
3567 if (compose->redirect_filename != NULL) {
3568 if (compose_redirect_write_to_file(compose, tmp2) < 0) {
3575 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3582 /* add queue header */
3583 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3584 G_DIR_SEPARATOR, (gint)compose);
3585 if ((fp = fopen(tmp, "wb")) == NULL) {
3586 FILE_OP_ERROR(tmp, "fopen");
3590 if ((src_fp = fopen(tmp2, "rb")) == NULL) {
3591 FILE_OP_ERROR(tmp2, "fopen");
3599 if (change_file_mode_rw(fp, tmp) < 0) {
3600 FILE_OP_ERROR(tmp, "chmod");
3601 g_warning("can't change file mode\n");
3604 /* queueing variables */
3605 fprintf(fp, "AF:\n");
3606 fprintf(fp, "NF:0\n");
3607 fprintf(fp, "PS:10\n");
3608 fprintf(fp, "SRH:1\n");
3609 fprintf(fp, "SFN:\n");
3610 fprintf(fp, "DSR:\n");
3612 fprintf(fp, "MID:<%s>\n", compose->msgid);
3614 fprintf(fp, "MID:\n");
3615 fprintf(fp, "CFG:\n");
3616 fprintf(fp, "PT:0\n");
3617 fprintf(fp, "S:%s\n", compose->account->address);
3618 fprintf(fp, "RQ:\n");
3620 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3622 fprintf(fp, "SSV:\n");
3624 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3626 fprintf(fp, "NSV:\n");
3627 fprintf(fp, "SSH:\n");
3628 /* write recepient list */
3629 if (compose->to_list) {
3630 fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
3631 for (cur = compose->to_list->next; cur != NULL;
3633 fprintf(fp, ",<%s>", (gchar *)cur->data);
3636 /* write newsgroup list */
3637 if (compose->newsgroup_list) {
3639 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3640 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3641 fprintf(fp, ",%s", (gchar *)cur->data);
3644 /* Sylpheed account IDs */
3646 fprintf(fp, "MAID:%d\n", mailac->account_id);
3649 fprintf(fp, "NAID:%d\n", newsac->account_id);
3651 /* Save copy folder */
3652 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3653 gchar *savefolderid;
3655 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3656 fprintf(fp, "SCF:%s\n", savefolderid);
3657 g_free(savefolderid);
3659 /* Message-ID of message replying to */
3660 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
3663 folderid = folder_item_get_identifier(compose->replyinfo->folder);
3664 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
3667 /* Message-ID of message forwarding to */
3668 if ((compose->fwdinfo != NULL) && (compose->fwdinfo->msgid != NULL)) {
3671 folderid = folder_item_get_identifier(compose->fwdinfo->folder);
3672 fprintf(fp, "FMID:%s\x7f%d\x7f%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
3677 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3678 if (fputs(buf, fp) == EOF) {
3679 FILE_OP_ERROR(tmp, "fputs");
3690 if (fclose(fp) == EOF) {
3691 FILE_OP_ERROR(tmp, "fclose");
3699 queue = account_get_special_folder(compose->account, F_QUEUE);
3701 g_warning("can't find queue folder\n");
3706 folder_item_scan(queue);
3707 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3708 g_warning("can't queue the message\n");
3718 if (compose->mode == COMPOSE_REEDIT) {
3719 compose_remove_reedit_target(compose);
3722 if ((msgnum != NULL) && (item != NULL)) {
3730 static void compose_write_attach(Compose *compose, FILE *fp)
3733 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3736 gchar filename[BUFFSIZE];
3739 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3741 gchar buf[BUFFSIZE];
3742 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3744 if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
3745 g_warning("Can't open file %s\n", ainfo->file);
3749 fprintf(fp, "\n--%s\n", compose->boundary);
3751 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3752 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3753 fprintf(fp, "Content-Disposition: inline\n");