2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2005 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.
26 #ifndef PANGO_ENABLE_ENGINE
27 # define PANGO_ENABLE_ENGINE
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtkmain.h>
34 #include <gtk/gtkmenu.h>
35 #include <gtk/gtkmenuitem.h>
36 #include <gtk/gtkitemfactory.h>
37 #include <gtk/gtkcheckmenuitem.h>
38 #include <gtk/gtkoptionmenu.h>
39 #include <gtk/gtkwidget.h>
40 #include <gtk/gtkvpaned.h>
41 #include <gtk/gtkentry.h>
42 #include <gtk/gtkeditable.h>
43 #include <gtk/gtkwindow.h>
44 #include <gtk/gtksignal.h>
45 #include <gtk/gtkvbox.h>
46 #include <gtk/gtkcontainer.h>
47 #include <gtk/gtkhandlebox.h>
48 #include <gtk/gtktoolbar.h>
49 #include <gtk/gtktable.h>
50 #include <gtk/gtkhbox.h>
51 #include <gtk/gtklabel.h>
52 #include <gtk/gtkscrolledwindow.h>
53 #include <gtk/gtktreeview.h>
54 #include <gtk/gtkliststore.h>
55 #include <gtk/gtktreeselection.h>
56 #include <gtk/gtktreemodel.h>
58 #include <gtk/gtkdnd.h>
59 #include <gtk/gtkclipboard.h>
60 #include <pango/pango-break.h>
65 #include <sys/types.h>
69 /* #include <sys/utsname.h> */
76 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
82 #include "mainwindow.h"
84 #include "addressbook.h"
85 #include "folderview.h"
88 #include "stock_pixmap.h"
89 #include "send_message.h"
92 #include "customheader.h"
93 #include "prefs_common.h"
94 #include "prefs_account.h"
98 #include "procheader.h"
100 #include "statusbar.h"
103 #include "quoted-printable.h"
104 #include "codeconv.h"
106 #include "gtkutils.h"
108 #include "alertpanel.h"
109 #include "manage_window.h"
110 #include "gtkshruler.h"
112 #include "addr_compl.h"
113 #include "quote_fmt.h"
114 #include "template.h"
116 #include "foldersel.h"
129 #define N_ATTACH_COLS (N_COL_COLUMNS)
133 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
134 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
135 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
136 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
137 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
138 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
139 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
140 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
141 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
142 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
143 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
144 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
145 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
146 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
147 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
148 } ComposeCallAdvancedAction;
152 PRIORITY_HIGHEST = 1,
161 COMPOSE_INSERT_SUCCESS,
162 COMPOSE_INSERT_READ_ERROR,
163 COMPOSE_INSERT_INVALID_CHARACTER,
164 COMPOSE_INSERT_NO_FILE
165 } ComposeInsertResult;
169 COMPOSE_QUIT_EDITING,
170 COMPOSE_KEEP_EDITING,
172 } ComposeDraftAction;
176 COMPOSE_WRITE_FOR_SEND,
177 COMPOSE_WRITE_FOR_STORE
180 #define B64_LINE_SIZE 57
181 #define B64_BUFFSIZE 77
183 #define MAX_REFERENCES_LEN 999
185 static GdkColor quote_color = {0, 0, 0, 0xbfff};
187 static GList *compose_list = NULL;
189 Compose *compose_generic_new (PrefsAccount *account,
192 GPtrArray *attach_files,
193 GList *listAddress );
195 static Compose *compose_create (PrefsAccount *account,
198 static GtkWidget *compose_account_option_menu_create
200 static void compose_set_template_menu (Compose *compose);
201 static void compose_template_apply (Compose *compose,
204 static void compose_destroy (Compose *compose);
206 static void compose_entries_set (Compose *compose,
207 const gchar *mailto);
208 static gint compose_parse_header (Compose *compose,
210 static gchar *compose_parse_references (const gchar *ref,
213 static gchar *compose_quote_fmt (Compose *compose,
219 static void compose_reply_set_entry (Compose *compose,
225 followup_and_reply_to);
226 static void compose_reedit_set_entry (Compose *compose,
229 static void compose_insert_sig (Compose *compose,
231 static gchar *compose_get_signature_str (Compose *compose);
232 static ComposeInsertResult compose_insert_file (Compose *compose,
235 static void compose_attach_append (Compose *compose,
238 const gchar *content_type);
239 static void compose_attach_parts (Compose *compose,
242 static void compose_wrap_paragraph (Compose *compose,
243 GtkTextIter *par_iter);
244 static void compose_wrap_all (Compose *compose);
245 static void compose_wrap_all_full (Compose *compose,
248 static void compose_set_title (Compose *compose);
249 static void compose_select_account (Compose *compose,
250 PrefsAccount *account,
253 static PrefsAccount *compose_current_mail_account(void);
254 /* static gint compose_send (Compose *compose); */
255 static gboolean compose_check_for_valid_recipient
257 static gboolean compose_check_entries (Compose *compose,
258 gboolean check_subject);
259 static gint compose_write_to_file (Compose *compose,
262 static gint compose_write_body_to_file (Compose *compose,
264 static gint compose_remove_reedit_target (Compose *compose);
265 void compose_remove_draft (Compose *compose);
266 static gint compose_queue (Compose *compose,
269 static gint compose_queue_sub (Compose *compose,
272 gboolean check_subject);
273 static void compose_add_attachments (Compose *compose,
275 static gchar *compose_get_header (Compose *compose);
277 static void compose_convert_header (gchar *dest,
281 gboolean addr_field);
283 static void compose_attach_info_free (AttachInfo *ainfo);
284 static void compose_attach_remove_selected (Compose *compose);
286 static void compose_attach_property (Compose *compose);
287 static void compose_attach_property_create (gboolean *cancelled);
288 static void attach_property_ok (GtkWidget *widget,
289 gboolean *cancelled);
290 static void attach_property_cancel (GtkWidget *widget,
291 gboolean *cancelled);
292 static gint attach_property_delete_event (GtkWidget *widget,
294 gboolean *cancelled);
295 static gboolean attach_property_key_pressed (GtkWidget *widget,
297 gboolean *cancelled);
299 static void compose_exec_ext_editor (Compose *compose);
300 static gint compose_exec_ext_editor_real (const gchar *file);
301 static gboolean compose_ext_editor_kill (Compose *compose);
302 static void compose_input_cb (gpointer data,
304 GdkInputCondition condition);
305 static void compose_set_ext_editor_sensitive (Compose *compose,
308 static void compose_undo_state_changed (UndoMain *undostruct,
313 static void compose_create_header_entry (Compose *compose);
314 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
315 static void compose_update_priority_menu_item(Compose * compose);
317 static void compose_add_field_list ( Compose *compose,
318 GList *listAddress );
320 /* callback functions */
322 static gboolean compose_edit_size_alloc (GtkEditable *widget,
323 GtkAllocation *allocation,
324 GtkSHRuler *shruler);
325 static void account_activated (GtkMenuItem *menuitem,
327 static void attach_selected (GtkTreeView *tree_view,
328 GtkTreePath *tree_path,
329 GtkTreeViewColumn *column,
331 static gboolean attach_button_pressed (GtkWidget *widget,
332 GdkEventButton *event,
334 static gboolean attach_key_pressed (GtkWidget *widget,
338 static void compose_send_cb (gpointer data,
341 static void compose_send_later_cb (gpointer data,
345 static void compose_draft_cb (gpointer data,
349 static void compose_attach_cb (gpointer data,
352 static void compose_insert_file_cb (gpointer data,
355 static void compose_insert_sig_cb (gpointer data,
359 static void compose_close_cb (gpointer data,
363 static void compose_address_cb (gpointer data,
366 static void compose_template_activate_cb(GtkWidget *widget,
369 static void compose_ext_editor_cb (gpointer data,
373 static gint compose_delete_cb (GtkWidget *widget,
376 static void compose_destroy_cb (GtkWidget *widget,
379 static void compose_undo_cb (Compose *compose);
380 static void compose_redo_cb (Compose *compose);
381 static void compose_cut_cb (Compose *compose);
382 static void compose_copy_cb (Compose *compose);
383 static void compose_paste_cb (Compose *compose);
384 static void compose_paste_as_quote_cb (Compose *compose);
385 static void compose_allsel_cb (Compose *compose);
387 static void compose_advanced_action_cb (Compose *compose,
388 ComposeCallAdvancedAction action);
390 static void compose_grab_focus_cb (GtkWidget *widget,
392 static void compose_grab_focus_before_cb(GtkWidget *widget,
395 static void compose_changed_cb (GtkTextBuffer *textbuf,
398 static void compose_wrap_cb (gpointer data,
401 static void compose_toggle_autowrap_cb (gpointer data,
406 static void compose_toggle_to_cb (gpointer data,
409 static void compose_toggle_cc_cb (gpointer data,
412 static void compose_toggle_bcc_cb (gpointer data,
415 static void compose_toggle_replyto_cb (gpointer data,
418 static void compose_toggle_followupto_cb(gpointer data,
421 static void compose_toggle_attach_cb (gpointer data,
425 static void compose_toggle_ruler_cb (gpointer data,
428 static void compose_toggle_sign_cb (gpointer data,
431 static void compose_toggle_encrypt_cb (gpointer data,
434 static void compose_set_privacy_system_cb(GtkWidget *widget,
436 static void compose_update_privacy_system_menu_item(Compose * compose);
437 static void activate_privacy_system (Compose *compose,
438 PrefsAccount *account);
439 static void compose_use_signing(Compose *compose, gboolean use_signing);
440 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
441 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
443 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
445 static void compose_set_priority_cb (gpointer data,
449 static void compose_attach_drag_received_cb (GtkWidget *widget,
450 GdkDragContext *drag_context,
453 GtkSelectionData *data,
457 static void compose_insert_drag_received_cb (GtkWidget *widget,
458 GdkDragContext *drag_context,
461 GtkSelectionData *data,
465 static void compose_header_drag_received_cb (GtkWidget *widget,
466 GdkDragContext *drag_context,
469 GtkSelectionData *data,
474 static gboolean compose_drag_drop (GtkWidget *widget,
475 GdkDragContext *drag_context,
477 guint time, gpointer user_data);
479 static void to_activated (GtkWidget *widget,
481 static void newsgroups_activated (GtkWidget *widget,
483 static void cc_activated (GtkWidget *widget,
485 static void bcc_activated (GtkWidget *widget,
487 static void replyto_activated (GtkWidget *widget,
489 static void followupto_activated (GtkWidget *widget,
491 static void subject_activated (GtkWidget *widget,
495 static void text_inserted (GtkTextBuffer *buffer,
500 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
501 gboolean to_all, gboolean to_ml,
503 gboolean followup_and_reply_to,
506 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
507 ComposeHeaderEntry *headerentry);
508 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
510 ComposeHeaderEntry *headerentry);
512 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
514 static void compose_allow_user_actions (Compose *compose, gboolean allow);
517 static void compose_check_all (Compose *compose);
518 static void compose_highlight_all (Compose *compose);
519 static void compose_check_backwards (Compose *compose);
520 static void compose_check_forwards_go (Compose *compose);
523 static gint compose_defer_auto_save_draft (Compose *compose);
524 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
526 static void compose_close (Compose *compose);
528 static GtkItemFactoryEntry compose_popup_entries[] =
530 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
531 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
532 {N_("/---"), NULL, NULL, 0, "<Separator>"},
533 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
536 static GtkItemFactoryEntry compose_entries[] =
538 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
539 {N_("/_Message/_Send"), "<control>Return",
540 compose_send_cb, 0, NULL},
541 {N_("/_Message/Send _later"), "<shift><control>S",
542 compose_send_later_cb, 0, NULL},
543 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
544 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
545 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
546 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
547 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
548 {N_("/_Message/_Save"),
549 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
550 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
551 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
553 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
554 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
555 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
556 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
557 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
558 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
559 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
560 {N_("/_Edit/Paste as _quotation"),
561 NULL, compose_paste_as_quote_cb, 0, NULL},
562 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
563 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
564 {N_("/_Edit/A_dvanced/Move a character backward"),
566 compose_advanced_action_cb,
567 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
569 {N_("/_Edit/A_dvanced/Move a character forward"),
571 compose_advanced_action_cb,
572 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
574 {N_("/_Edit/A_dvanced/Move a word backward"),
576 compose_advanced_action_cb,
577 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
579 {N_("/_Edit/A_dvanced/Move a word forward"),
581 compose_advanced_action_cb,
582 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
584 {N_("/_Edit/A_dvanced/Move to beginning of line"),
585 NULL, /* "<control>A" */
586 compose_advanced_action_cb,
587 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
589 {N_("/_Edit/A_dvanced/Move to end of line"),
591 compose_advanced_action_cb,
592 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
594 {N_("/_Edit/A_dvanced/Move to previous line"),
596 compose_advanced_action_cb,
597 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
599 {N_("/_Edit/A_dvanced/Move to next line"),
601 compose_advanced_action_cb,
602 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
604 {N_("/_Edit/A_dvanced/Delete a character backward"),
606 compose_advanced_action_cb,
607 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
609 {N_("/_Edit/A_dvanced/Delete a character forward"),
611 compose_advanced_action_cb,
612 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
614 {N_("/_Edit/A_dvanced/Delete a word backward"),
615 NULL, /* "<control>W" */
616 compose_advanced_action_cb,
617 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
619 {N_("/_Edit/A_dvanced/Delete a word forward"),
620 NULL, /* "<alt>D", */
621 compose_advanced_action_cb,
622 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
624 {N_("/_Edit/A_dvanced/Delete line"),
626 compose_advanced_action_cb,
627 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
629 {N_("/_Edit/A_dvanced/Delete entire line"),
631 compose_advanced_action_cb,
632 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
634 {N_("/_Edit/A_dvanced/Delete to end of line"),
636 compose_advanced_action_cb,
637 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
639 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
640 {N_("/_Edit/_Wrap current paragraph"),
641 "<control>L", compose_wrap_cb, 0, NULL},
642 {N_("/_Edit/Wrap all long _lines"),
643 "<control><alt>L", compose_wrap_cb, 1, NULL},
644 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
645 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
646 {N_("/_Edit/Edit with e_xternal editor"),
647 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
649 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
650 {N_("/_Spelling/_Check all or check selection"),
651 NULL, compose_check_all, 0, NULL},
652 {N_("/_Spelling/_Highlight all misspelled words"),
653 NULL, compose_highlight_all, 0, NULL},
654 {N_("/_Spelling/Check _backwards misspelled word"),
655 NULL, compose_check_backwards , 0, NULL},
656 {N_("/_Spelling/_Forward to next misspelled word"),
657 NULL, compose_check_forwards_go, 0, NULL},
658 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
659 {N_("/_Spelling/_Spelling Configuration"),
660 NULL, NULL, 0, "<Branch>"},
662 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
663 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
664 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
665 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
666 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
667 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
668 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
669 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
670 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
671 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
672 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
673 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
674 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
675 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
676 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
677 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
678 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
679 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
680 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
681 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
682 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
683 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
686 static GtkTargetEntry compose_mime_types[] =
688 {"text/uri-list", 0, 0},
689 {"text/plain", 0, 0},
693 static gboolean compose_put_existing_to_front(MsgInfo *info)
695 GList *compose_list = compose_get_compose_list();
699 for (elem = compose_list; elem != NULL && elem->data != NULL;
701 Compose *c = (Compose*)elem->data;
703 if (!c->targetinfo || !c->targetinfo->msgid ||
707 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
708 gtkut_window_popup(c->window);
716 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
717 GPtrArray *attach_files)
719 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
722 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
724 return compose_generic_new(account, NULL, item, NULL, NULL);
727 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
729 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
732 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
733 GPtrArray *attach_files, GList *listAddress )
736 GtkTextView *textview;
737 GtkTextBuffer *textbuf;
739 GtkItemFactory *ifactory;
741 if (item && item->prefs && item->prefs->enable_default_account)
742 account = account_find_from_id(item->prefs->default_account);
744 if (!account) account = cur_account;
745 g_return_val_if_fail(account != NULL, NULL);
747 compose = compose_create(account, COMPOSE_NEW);
748 ifactory = gtk_item_factory_from_widget(compose->menubar);
750 compose->replyinfo = NULL;
751 compose->fwdinfo = NULL;
753 textview = GTK_TEXT_VIEW(compose->text);
754 textbuf = gtk_text_view_get_buffer(textview);
756 undo_block(compose->undostruct);
758 if (item && item->prefs && item->prefs->enable_default_dictionary &&
760 gtkaspell_change_dict(compose->gtkaspell,
761 item->prefs->default_dictionary);
764 if (account->auto_sig)
765 compose_insert_sig(compose, FALSE);
766 gtk_text_buffer_get_start_iter(textbuf, &iter);
767 gtk_text_buffer_place_cursor(textbuf, &iter);
769 if (account->protocol != A_NNTP) {
770 if (mailto && *mailto != '\0') {
771 compose_entries_set(compose, mailto);
773 } else if (item && item->prefs->enable_default_to) {
774 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
775 compose_entry_mark_default_to(compose, item->prefs->default_to);
777 if (item && item->ret_rcpt) {
778 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
782 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
785 * CLAWS: just don't allow return receipt request, even if the user
786 * may want to send an email. simple but foolproof.
788 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
790 compose_add_field_list( compose, listAddress );
796 for (i = 0; i < attach_files->len; i++) {
797 file = g_ptr_array_index(attach_files, i);
798 compose_attach_append(compose, file, file, NULL);
802 compose_show_first_last_header(compose, TRUE);
804 /* Set save folder */
805 if (item && item->prefs && item->prefs->save_copy_to_folder) {
806 gchar *folderidentifier;
808 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
809 folderidentifier = folder_item_get_identifier(item);
810 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
811 g_free(folderidentifier);
814 gtk_widget_grab_focus(compose->header_last->entry);
816 undo_unblock(compose->undostruct);
818 if (prefs_common.auto_exteditor)
819 compose_exec_ext_editor(compose);
825 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
826 const gchar *followupto, gchar * to)
830 if (!account) account = cur_account;
831 g_return_val_if_fail(account != NULL, NULL);
832 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
834 compose = compose_create(account, COMPOSE_NEW);
836 if (prefs_common.auto_sig)
837 compose_insert_sig(compose);
838 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
839 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
841 compose_entry_append(compose, to, COMPOSE_TO);
842 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
843 gtk_widget_grab_focus(compose->subject_entry);
849 void compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
854 g_return_if_fail(msginfo_list != NULL);
856 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
857 g_return_if_fail(msginfo != NULL);
859 list_len = g_slist_length(msginfo_list);
863 compose_reply(msginfo, prefs_common.reply_with_quote,
864 FALSE, prefs_common.default_reply_list, FALSE, body);
866 case COMPOSE_REPLY_WITH_QUOTE:
867 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, body);
869 case COMPOSE_REPLY_WITHOUT_QUOTE:
870 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
872 case COMPOSE_REPLY_TO_SENDER:
873 compose_reply(msginfo, prefs_common.reply_with_quote,
874 FALSE, FALSE, TRUE, body);
876 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
877 compose_followup_and_reply_to(msginfo,
878 prefs_common.reply_with_quote,
881 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
882 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, body);
884 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
885 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
887 case COMPOSE_REPLY_TO_ALL:
888 compose_reply(msginfo, prefs_common.reply_with_quote,
889 TRUE, FALSE, FALSE, body);
891 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
892 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, body);
894 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
895 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
897 case COMPOSE_REPLY_TO_LIST:
898 compose_reply(msginfo, prefs_common.reply_with_quote,
899 FALSE, TRUE, FALSE, body);
901 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
902 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, body);
904 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
905 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
907 case COMPOSE_FORWARD:
908 if (prefs_common.forward_as_attachment) {
909 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
912 compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
916 case COMPOSE_FORWARD_INLINE:
917 /* check if we reply to more than one Message */
919 compose_forward(NULL, msginfo, FALSE, body, FALSE);
922 /* more messages FALL THROUGH */
923 case COMPOSE_FORWARD_AS_ATTACH:
924 compose_forward_multiple(NULL, msginfo_list);
926 case COMPOSE_REDIRECT:
927 compose_redirect(NULL, msginfo);
930 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
934 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
935 gboolean to_ml, gboolean to_sender,
938 compose_generic_reply(msginfo, quote, to_all, to_ml,
939 to_sender, FALSE, body);
942 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
947 compose_generic_reply(msginfo, quote, to_all, FALSE,
948 to_sender, TRUE, body);
951 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
952 gboolean to_all, gboolean to_ml,
954 gboolean followup_and_reply_to,
957 GtkItemFactory *ifactory;
959 PrefsAccount *account = NULL;
960 PrefsAccount *reply_account;
961 GtkTextView *textview;
962 GtkTextBuffer *textbuf;
966 g_return_if_fail(msginfo != NULL);
967 g_return_if_fail(msginfo->folder != NULL);
969 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
971 g_return_if_fail(account != NULL);
973 if (to_sender && account->protocol == A_NNTP &&
974 !followup_and_reply_to) {
976 account_find_from_address(account->address);
978 reply_account = compose_current_mail_account();
982 reply_account = account;
984 compose = compose_create(account, COMPOSE_REPLY);
985 ifactory = gtk_item_factory_from_widget(compose->menubar);
987 menu_set_active(ifactory, "/Options/Remove references", FALSE);
988 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
990 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
991 if (!compose->replyinfo)
992 compose->replyinfo = procmsg_msginfo_copy(msginfo);
994 if (msginfo->folder && msginfo->folder->ret_rcpt)
995 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
997 /* Set save folder */
998 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
999 gchar *folderidentifier;
1001 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1002 folderidentifier = folder_item_get_identifier(msginfo->folder);
1003 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1004 g_free(folderidentifier);
1007 if (compose_parse_header(compose, msginfo) < 0) return;
1008 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
1009 to_sender, followup_and_reply_to);
1010 compose_show_first_last_header(compose, TRUE);
1012 textview = (GTK_TEXT_VIEW(compose->text));
1013 textbuf = gtk_text_view_get_buffer(textview);
1015 undo_block(compose->undostruct);
1017 if (msginfo->folder && msginfo->folder->prefs &&
1018 msginfo->folder->prefs &&
1019 msginfo->folder->prefs->enable_default_dictionary &&
1021 gtkaspell_change_dict(compose->gtkaspell,
1022 msginfo->folder->prefs->default_dictionary);
1028 if (prefs_common.quotemark && *prefs_common.quotemark)
1029 qmark = prefs_common.quotemark;
1033 compose_quote_fmt(compose, compose->replyinfo,
1034 prefs_common.quotefmt,
1038 if (account->auto_sig)
1039 compose_insert_sig(compose, FALSE);
1041 cursor_pos = quote_fmt_get_cursor_pos();
1042 gtk_text_buffer_get_start_iter(textbuf, &iter);
1043 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cursor_pos);
1044 gtk_text_buffer_place_cursor(textbuf, &iter);
1046 if (quote && prefs_common.linewrap_quote)
1047 compose_wrap_all(compose);
1049 gtk_widget_grab_focus(compose->text);
1051 undo_unblock(compose->undostruct);
1053 if (prefs_common.auto_exteditor)
1054 compose_exec_ext_editor(compose);
1057 #define INSERT_FW_HEADER(var, hdr) \
1058 if (msginfo->var && *msginfo->var) { \
1059 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1060 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1061 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1064 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1065 gboolean as_attach, const gchar *body,
1066 gboolean no_extedit)
1069 GtkTextView *textview;
1070 GtkTextBuffer *textbuf;
1073 g_return_val_if_fail(msginfo != NULL, NULL);
1074 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1077 !(account = compose_guess_forward_account_from_msginfo
1079 account = cur_account;
1081 compose = compose_create(account, COMPOSE_FORWARD);
1083 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1084 if (!compose->fwdinfo)
1085 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1087 if (msginfo->subject && *msginfo->subject) {
1088 gchar *buf, *buf2, *p;
1090 buf = p = g_strdup(msginfo->subject);
1091 p += subject_get_prefix_length(p);
1092 memmove(buf, p, strlen(p) + 1);
1094 buf2 = g_strdup_printf("Fw: %s", buf);
1095 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1101 textview = GTK_TEXT_VIEW(compose->text);
1102 textbuf = gtk_text_view_get_buffer(textview);
1107 msgfile = procmsg_get_message_file_path(msginfo);
1108 if (!is_file_exist(msgfile))
1109 g_warning("%s: file not exist\n", msgfile);
1111 compose_attach_append(compose, msgfile, msgfile,
1117 MsgInfo *full_msginfo;
1119 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1121 full_msginfo = procmsg_msginfo_copy(msginfo);
1123 if (prefs_common.fw_quotemark &&
1124 *prefs_common.fw_quotemark)
1125 qmark = prefs_common.fw_quotemark;
1129 compose_quote_fmt(compose, full_msginfo,
1130 prefs_common.fw_quotefmt,
1132 compose_attach_parts(compose, msginfo);
1134 procmsg_msginfo_free(full_msginfo);
1137 if (account->auto_sig)
1138 compose_insert_sig(compose, FALSE);
1140 if (prefs_common.linewrap_quote)
1141 compose_wrap_all(compose);
1143 gtk_text_buffer_get_start_iter(textbuf, &iter);
1144 gtk_text_buffer_place_cursor(textbuf, &iter);
1146 #if 0 /* NEW COMPOSE GUI */
1147 if (account->protocol != A_NNTP)
1148 gtk_widget_grab_focus(compose->to_entry);
1150 gtk_widget_grab_focus(compose->newsgroups_entry);
1152 gtk_widget_grab_focus(compose->header_last->entry);
1154 if (!no_extedit && prefs_common.auto_exteditor)
1155 compose_exec_ext_editor(compose);
1158 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1159 gchar *folderidentifier;
1161 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1162 folderidentifier = folder_item_get_identifier(msginfo->folder);
1163 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1164 g_free(folderidentifier);
1170 #undef INSERT_FW_HEADER
1172 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1175 GtkTextView *textview;
1176 GtkTextBuffer *textbuf;
1181 g_return_val_if_fail(msginfo_list != NULL, NULL);
1183 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1184 if (((MsgInfo *)msginfo->data)->folder == NULL)
1187 /* guess account from first selected message */
1189 !(account = compose_guess_forward_account_from_msginfo
1190 (msginfo_list->data)))
1191 account = cur_account;
1193 g_return_val_if_fail(account != NULL, NULL);
1195 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1196 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1197 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1200 compose = compose_create(account, COMPOSE_FORWARD);
1202 textview = GTK_TEXT_VIEW(compose->text);
1203 textbuf = gtk_text_view_get_buffer(textview);
1205 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1206 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1207 if (!is_file_exist(msgfile))
1208 g_warning("%s: file not exist\n", msgfile);
1210 compose_attach_append(compose, msgfile, msgfile,
1215 if (account->auto_sig)
1216 compose_insert_sig(compose, FALSE);
1218 if (prefs_common.linewrap_quote)
1219 compose_wrap_all(compose);
1221 gtk_text_buffer_get_start_iter(textbuf, &iter);
1222 gtk_text_buffer_place_cursor(textbuf, &iter);
1224 gtk_widget_grab_focus(compose->header_last->entry);
1226 #if 0 /* NEW COMPOSE GUI */
1227 if (account->protocol != A_NNTP)
1228 gtk_widget_grab_focus(compose->to_entry);
1230 gtk_widget_grab_focus(compose->newsgroups_entry);
1236 void compose_reedit(MsgInfo *msginfo)
1239 PrefsAccount *account = NULL;
1240 GtkTextView *textview;
1241 GtkTextBuffer *textbuf;
1245 gchar buf[BUFFSIZE];
1246 gboolean use_signing = FALSE;
1247 gboolean use_encryption = FALSE;
1248 gchar *privacy_system = NULL;
1250 g_return_if_fail(msginfo != NULL);
1251 g_return_if_fail(msginfo->folder != NULL);
1253 if (compose_put_existing_to_front(msginfo))
1256 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1257 gchar queueheader_buf[BUFFSIZE];
1260 /* Select Account from queue headers */
1261 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1262 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1263 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1264 account = account_find_from_id(id);
1266 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1267 sizeof(queueheader_buf), "NAID:")) {
1268 id = atoi(&queueheader_buf[strlen("NAID:")]);
1269 account = account_find_from_id(id);
1271 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1272 sizeof(queueheader_buf), "MAID:")) {
1273 id = atoi(&queueheader_buf[strlen("MAID:")]);
1274 account = account_find_from_id(id);
1276 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1277 sizeof(queueheader_buf), "S:")) {
1278 account = account_find_from_address(queueheader_buf);
1280 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1281 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1282 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1283 use_signing = param;
1286 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1287 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1288 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1289 use_encryption = param;
1291 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1292 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1293 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1295 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1296 sizeof(queueheader_buf), "X-Priority: ")) {
1297 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1298 compose->priority = param;
1301 account = msginfo->folder->folder->account;
1303 if (!account && prefs_common.reedit_account_autosel) {
1304 gchar from[BUFFSIZE];
1305 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1306 extract_address(from);
1307 account = account_find_from_address(from);
1310 if (!account) account = cur_account;
1311 g_return_if_fail(account != NULL);
1313 compose = compose_create(account, COMPOSE_REEDIT);
1314 compose->privacy_system = privacy_system;
1315 compose_use_signing(compose, use_signing);
1316 compose_use_encryption(compose, use_encryption);
1317 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1319 if (msginfo->folder->stype == F_QUEUE
1320 || msginfo->folder->stype == F_DRAFT) {
1321 gchar queueheader_buf[BUFFSIZE];
1323 /* Set message save folder */
1324 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1327 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1328 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1329 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1333 if (compose_parse_header(compose, msginfo) < 0) return;
1334 compose_reedit_set_entry(compose, msginfo);
1336 textview = GTK_TEXT_VIEW(compose->text);
1337 textbuf = gtk_text_view_get_buffer(textview);
1338 mark = gtk_text_buffer_get_insert(textbuf);
1339 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1341 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1342 G_CALLBACK(compose_changed_cb),
1345 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1346 g_warning("Can't get text part\n");
1348 while (fgets(buf, sizeof(buf), fp) != NULL) {
1350 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1355 compose_attach_parts(compose, msginfo);
1357 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1358 G_CALLBACK(compose_changed_cb),
1361 gtk_widget_grab_focus(compose->text);
1363 if (prefs_common.auto_exteditor)
1364 compose_exec_ext_editor(compose);
1367 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1371 GtkItemFactory *ifactory;
1374 g_return_val_if_fail(msginfo != NULL, NULL);
1377 account = account_get_reply_account(msginfo,
1378 prefs_common.reply_account_autosel);
1379 g_return_val_if_fail(account != NULL, NULL);
1381 compose = compose_create(account, COMPOSE_REDIRECT);
1382 ifactory = gtk_item_factory_from_widget(compose->menubar);
1384 compose->replyinfo = NULL;
1385 compose->fwdinfo = NULL;
1387 compose_show_first_last_header(compose, TRUE);
1389 gtk_widget_grab_focus(compose->header_last->entry);
1391 filename = procmsg_get_message_file_path(msginfo);
1392 if (filename == NULL)
1395 compose->redirect_filename = filename;
1397 /* Set save folder */
1398 item = msginfo->folder;
1399 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1400 gchar *folderidentifier;
1402 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1403 folderidentifier = folder_item_get_identifier(item);
1404 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1405 g_free(folderidentifier);
1408 compose_attach_parts(compose, msginfo);
1410 if (msginfo->subject)
1411 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1413 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1415 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1416 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1418 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1419 menu_set_sensitive(ifactory, "/Add...", FALSE);
1420 menu_set_sensitive(ifactory, "/Remove", FALSE);
1421 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1423 ifactory = gtk_item_factory_from_widget(compose->menubar);
1424 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1425 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1426 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1427 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1428 menu_set_sensitive(ifactory, "/Edit", FALSE);
1429 menu_set_sensitive(ifactory, "/Options", FALSE);
1430 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1431 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1433 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1434 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1435 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1436 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1437 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1438 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1439 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1444 GList *compose_get_compose_list(void)
1446 return compose_list;
1449 void compose_entry_append(Compose *compose, const gchar *address,
1450 ComposeEntryType type)
1454 if (!address || *address == '\0') return;
1456 #if 0 /* NEW COMPOSE GUI */
1459 entry = GTK_ENTRY(compose->cc_entry);
1462 entry = GTK_ENTRY(compose->bcc_entry);
1464 case COMPOSE_NEWSGROUPS:
1465 entry = GTK_ENTRY(compose->newsgroups_entry);
1469 entry = GTK_ENTRY(compose->to_entry);
1473 text = gtk_entry_get_text(entry);
1475 gtk_entry_append_text(entry, ", ");
1476 gtk_entry_append_text(entry, address);
1484 header = N_("Bcc:");
1486 case COMPOSE_REPLYTO:
1487 header = N_("Reply-To:");
1489 case COMPOSE_NEWSGROUPS:
1490 header = N_("Newsgroups:");
1492 case COMPOSE_FOLLOWUPTO:
1493 header = N_( "Followup-To:");
1500 header = prefs_common.trans_hdr ? gettext(header) : header;
1502 compose_add_header_entry(compose, header, (gchar *)address);
1505 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1507 static GtkStyle *bold_style = NULL;
1508 static GdkColor bold_color;
1512 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1513 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1514 if (gtk_entry_get_text(entry) &&
1515 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1516 gtk_widget_ensure_style(GTK_WIDGET(entry));
1518 PangoFontDescription *font_desc = NULL;
1519 gtkut_convert_int_to_gdk_color
1520 (prefs_common.color_new, &bold_color);
1521 bold_style = gtk_style_copy(gtk_widget_get_style
1522 (GTK_WIDGET(entry)));
1524 font_desc = pango_font_description_from_string
1527 if (bold_style->font_desc)
1528 pango_font_description_free
1529 (bold_style->font_desc);
1530 bold_style->font_desc = font_desc;
1532 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1534 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1539 void compose_toolbar_cb(gint action, gpointer data)
1541 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1542 Compose *compose = (Compose*)toolbar_item->parent;
1544 g_return_if_fail(compose != NULL);
1548 compose_send_cb(compose, 0, NULL);
1551 compose_send_later_cb(compose, 0, NULL);
1554 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1557 compose_insert_file_cb(compose, 0, NULL);
1560 compose_attach_cb(compose, 0, NULL);
1563 compose_insert_sig(compose, FALSE);
1566 compose_ext_editor_cb(compose, 0, NULL);
1568 case A_LINEWRAP_CURRENT:
1569 compose_wrap_paragraph(compose, NULL);
1571 case A_LINEWRAP_ALL:
1572 compose_wrap_all(compose);
1575 compose_address_cb(compose, 0, NULL);
1578 case A_CHECK_SPELLING:
1579 compose_check_all(compose);
1587 static void compose_entries_set(Compose *compose, const gchar *mailto)
1592 gchar *subject = NULL;
1597 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1600 compose_entry_append(compose, to, COMPOSE_TO);
1602 compose_entry_append(compose, cc, COMPOSE_CC);
1604 compose_entry_append(compose, bcc, COMPOSE_BCC);
1606 if (!g_utf8_validate (subject, -1, NULL)) {
1607 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
1608 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
1611 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1614 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1615 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1619 mark = gtk_text_buffer_get_insert(buffer);
1620 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1622 if (!g_utf8_validate (body, -1, NULL)) {
1623 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
1624 gtk_text_buffer_insert(buffer, &iter, temp, -1);
1627 gtk_text_buffer_insert(buffer, &iter, body, -1);
1629 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1639 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1641 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1642 {"Cc:", NULL, TRUE},
1643 {"References:", NULL, FALSE},
1644 {"Bcc:", NULL, TRUE},
1645 {"Newsgroups:", NULL, TRUE},
1646 {"Followup-To:", NULL, TRUE},
1647 {"List-Post:", NULL, FALSE},
1648 {"X-Priority:", NULL, FALSE},
1649 {NULL, NULL, FALSE}};
1665 g_return_val_if_fail(msginfo != NULL, -1);
1667 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1668 procheader_get_header_fields(fp, hentry);
1671 if (hentry[H_REPLY_TO].body != NULL) {
1672 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1673 compose->replyto = hentry[H_REPLY_TO].body;
1674 hentry[H_REPLY_TO].body = NULL;
1676 if (hentry[H_CC].body != NULL) {
1677 conv_unmime_header_overwrite(hentry[H_CC].body);
1678 compose->cc = hentry[H_CC].body;
1679 hentry[H_CC].body = NULL;
1681 if (hentry[H_REFERENCES].body != NULL) {
1682 if (compose->mode == COMPOSE_REEDIT)
1683 compose->references = hentry[H_REFERENCES].body;
1685 compose->references = compose_parse_references
1686 (hentry[H_REFERENCES].body, msginfo->msgid);
1687 g_free(hentry[H_REFERENCES].body);
1689 hentry[H_REFERENCES].body = NULL;
1691 if (hentry[H_BCC].body != NULL) {
1692 if (compose->mode == COMPOSE_REEDIT) {
1693 conv_unmime_header_overwrite(hentry[H_BCC].body);
1694 compose->bcc = hentry[H_BCC].body;
1696 g_free(hentry[H_BCC].body);
1697 hentry[H_BCC].body = NULL;
1699 if (hentry[H_NEWSGROUPS].body != NULL) {
1700 conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
1701 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1702 hentry[H_NEWSGROUPS].body = NULL;
1704 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1705 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1706 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1707 hentry[H_FOLLOWUP_TO].body = NULL;
1709 if (hentry[H_LIST_POST].body != NULL) {
1712 extract_address(hentry[H_LIST_POST].body);
1713 if (hentry[H_LIST_POST].body[0] != '\0') {
1714 scan_mailto_url(hentry[H_LIST_POST].body,
1715 &to, NULL, NULL, NULL, NULL);
1717 g_free(compose->ml_post);
1718 compose->ml_post = to;
1721 g_free(hentry[H_LIST_POST].body);
1722 hentry[H_LIST_POST].body = NULL;
1725 /* CLAWS - X-Priority */
1726 if (compose->mode == COMPOSE_REEDIT)
1727 if (hentry[H_X_PRIORITY].body != NULL) {
1730 priority = atoi(hentry[H_X_PRIORITY].body);
1731 g_free(hentry[H_X_PRIORITY].body);
1733 hentry[H_X_PRIORITY].body = NULL;
1735 if (priority < PRIORITY_HIGHEST ||
1736 priority > PRIORITY_LOWEST)
1737 priority = PRIORITY_NORMAL;
1739 compose->priority = priority;
1742 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1743 compose->inreplyto = g_strdup(msginfo->inreplyto);
1744 else if (compose->mode != COMPOSE_REEDIT &&
1745 msginfo->msgid && *msginfo->msgid) {
1746 compose->inreplyto = g_strdup(msginfo->msgid);
1748 if (!compose->references) {
1749 if (msginfo->inreplyto && *msginfo->inreplyto)
1750 compose->references =
1751 g_strdup_printf("<%s>\n\t<%s>",
1755 compose->references =
1756 g_strconcat("<", msginfo->msgid, ">",
1764 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1766 GSList *ref_id_list, *cur;
1770 ref_id_list = references_list_append(NULL, ref);
1771 if (!ref_id_list) return NULL;
1772 if (msgid && *msgid)
1773 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1778 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1779 /* "<" + Message-ID + ">" + CR+LF+TAB */
1780 len += strlen((gchar *)cur->data) + 5;
1782 if (len > MAX_REFERENCES_LEN) {
1783 /* remove second message-ID */
1784 if (ref_id_list && ref_id_list->next &&
1785 ref_id_list->next->next) {
1786 g_free(ref_id_list->next->data);
1787 ref_id_list = g_slist_remove
1788 (ref_id_list, ref_id_list->next->data);
1790 slist_free_strings(ref_id_list);
1791 g_slist_free(ref_id_list);
1798 new_ref = g_string_new("");
1799 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1800 if (new_ref->len > 0)
1801 g_string_append(new_ref, "\n\t");
1802 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
1805 slist_free_strings(ref_id_list);
1806 g_slist_free(ref_id_list);
1808 new_ref_str = new_ref->str;
1809 g_string_free(new_ref, FALSE);
1814 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1815 const gchar *fmt, const gchar *qmark,
1818 static MsgInfo dummyinfo;
1819 gchar *quote_str = NULL;
1823 const gchar *trimmed_body = body;
1826 msginfo = &dummyinfo;
1828 if (qmark != NULL) {
1829 quote_fmt_init(msginfo, NULL, NULL);
1830 quote_fmt_scan_string(qmark);
1833 buf = quote_fmt_get_buffer();
1835 alertpanel_error(_("Quote mark format error."));
1837 Xstrdup_a(quote_str, buf, return NULL)
1840 if (fmt && *fmt != '\0') {
1841 while (trimmed_body && strlen(trimmed_body) > 1
1842 && trimmed_body[0]=='\n')
1845 quote_fmt_init(msginfo, quote_str, trimmed_body);
1846 quote_fmt_scan_string(fmt);
1849 buf = quote_fmt_get_buffer();
1851 alertpanel_error(_("Message reply/forward format error."));
1857 for (p = buf; *p != '\0'; ) {
1858 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1859 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1863 g_signal_handlers_block_by_func(G_OBJECT(buffer),
1864 G_CALLBACK(compose_changed_cb),
1866 g_signal_handlers_block_by_func(G_OBJECT(buffer),
1867 G_CALLBACK(text_inserted),
1870 mark = gtk_text_buffer_get_insert(buffer);
1871 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1873 lastp = strchr(p, '\n');
1874 len = lastp ? lastp - p + 1 : -1;
1876 gtk_text_buffer_insert(buffer, &iter, p, len);
1878 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
1879 G_CALLBACK(compose_changed_cb),
1881 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
1882 G_CALLBACK(text_inserted),
1894 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1895 gboolean to_all, gboolean to_ml,
1897 gboolean followup_and_reply_to)
1899 GSList *cc_list = NULL;
1902 gchar *replyto = NULL;
1903 GHashTable *to_table;
1905 g_return_if_fail(compose->account != NULL);
1906 g_return_if_fail(msginfo != NULL);
1908 if (compose->account->protocol != A_NNTP) {
1909 if (!compose->replyto && to_ml && compose->ml_post
1910 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1911 compose_entry_append(compose,
1914 else if (!(to_all || to_sender)
1916 && msginfo->folder->prefs->enable_default_reply_to) {
1917 compose_entry_append(compose,
1918 msginfo->folder->prefs->default_reply_to,
1921 compose_entry_append(compose,
1922 (compose->replyto && !to_sender)
1923 ? compose->replyto :
1924 msginfo->from ? msginfo->from : "",
1927 if (to_sender || (compose->followup_to &&
1928 !strncmp(compose->followup_to, "poster", 6)))
1929 compose_entry_append
1931 (compose->replyto ? compose->replyto :
1932 msginfo->from ? msginfo->from : ""),
1935 else if (followup_and_reply_to || to_all) {
1936 compose_entry_append
1938 (compose->replyto ? compose->replyto :
1939 msginfo->from ? msginfo->from : ""),
1942 compose_entry_append
1944 compose->followup_to ? compose->followup_to :
1945 compose->newsgroups ? compose->newsgroups : "",
1946 COMPOSE_NEWSGROUPS);
1949 compose_entry_append
1951 compose->followup_to ? compose->followup_to :
1952 compose->newsgroups ? compose->newsgroups : "",
1953 COMPOSE_NEWSGROUPS);
1956 if (msginfo->subject && *msginfo->subject) {
1960 buf = p = g_strdup(msginfo->subject);
1961 p += subject_get_prefix_length(p);
1962 memmove(buf, p, strlen(p) + 1);
1964 buf2 = g_strdup_printf("Re: %s", buf);
1965 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1970 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1972 if (to_ml && compose->ml_post) return;
1973 if (!to_all || compose->account->protocol == A_NNTP) return;
1975 if (compose->replyto) {
1976 Xstrdup_a(replyto, compose->replyto, return);
1977 extract_address(replyto);
1979 if (msginfo->from) {
1980 Xstrdup_a(from, msginfo->from, return);
1981 extract_address(from);
1984 if (replyto && from)
1985 cc_list = address_list_append_with_comments(cc_list, from);
1986 if (to_all && msginfo->folder &&
1987 msginfo->folder->prefs->enable_default_reply_to)
1988 cc_list = address_list_append_with_comments(cc_list,
1989 msginfo->folder->prefs->default_reply_to);
1990 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
1991 cc_list = address_list_append_with_comments(cc_list, compose->cc);
1993 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1995 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
1996 if (compose->account)
1997 g_hash_table_insert(to_table, g_strdup(compose->account->address),
1998 GINT_TO_POINTER(1));
2000 /* remove address on To: and that of current account */
2001 for (cur = cc_list; cur != NULL; ) {
2002 GSList *next = cur->next;
2005 addr = g_strdup(cur->data);
2006 extract_address(addr);
2008 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
2009 cc_list = g_slist_remove(cc_list, cur->data);
2011 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2015 hash_free_strings(to_table);
2016 g_hash_table_destroy(to_table);
2019 for (cur = cc_list; cur != NULL; cur = cur->next)
2020 compose_entry_append(compose, (gchar *)cur->data,
2022 slist_free_strings(cc_list);
2023 g_slist_free(cc_list);
2028 #define SET_ENTRY(entry, str) \
2031 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2034 #define SET_ADDRESS(type, str) \
2037 compose_entry_append(compose, str, type); \
2040 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2042 g_return_if_fail(msginfo != NULL);
2044 SET_ENTRY(subject_entry, msginfo->subject);
2045 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2046 SET_ADDRESS(COMPOSE_CC, compose->cc);
2047 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2048 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2049 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2050 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2052 compose_update_priority_menu_item(compose);
2053 compose_update_privacy_system_menu_item(compose);
2054 compose_show_first_last_header(compose, TRUE);
2060 static void compose_insert_sig(Compose *compose, gboolean replace)
2062 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2063 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2069 g_return_if_fail(compose->account != NULL);
2071 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2072 G_CALLBACK(compose_changed_cb),
2075 mark = gtk_text_buffer_get_insert(buffer);
2076 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2077 cur_pos = gtk_text_iter_get_offset (&iter);
2079 gtk_text_buffer_get_end_iter(buffer, &iter);
2081 if (replace && compose->sig_str) {
2083 GtkTextIter first_iter, start_iter, end_iter;
2085 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2087 if (compose->sig_str[0] == '\0')
2090 found = gtk_text_iter_forward_search(&first_iter,
2092 GTK_TEXT_SEARCH_TEXT_ONLY,
2093 &start_iter, &end_iter,
2097 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2102 g_free(compose->sig_str);
2103 compose->sig_str = compose_get_signature_str(compose);
2104 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2105 compose->sig_str = g_strdup("");
2107 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2109 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2110 cur_pos = gtk_text_buffer_get_char_count (buffer);
2112 gtk_text_buffer_get_iter_at_offset (buffer, &iter, cur_pos);
2113 gtk_text_buffer_place_cursor (buffer, &iter);
2115 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2116 G_CALLBACK(compose_changed_cb),
2121 static gchar *compose_get_signature_str(Compose *compose)
2123 gchar *sig_body = NULL;
2124 gchar *sig_str = NULL;
2126 g_return_val_if_fail(compose->account != NULL, NULL);
2128 if (!compose->account->sig_path)
2131 if (compose->account->sig_type == SIG_FILE) {
2132 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2133 g_warning("can't open signature file: %s\n",
2134 compose->account->sig_path);
2139 if (compose->account->sig_type == SIG_COMMAND)
2140 sig_body = get_command_output(compose->account->sig_path);
2144 tmp = file_read_to_str(compose->account->sig_path);
2147 sig_body = normalize_newlines(tmp);
2151 if (compose->account->sig_sep)
2152 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2155 sig_str = g_strconcat("\n\n", sig_body, NULL);
2162 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2165 GtkTextBuffer *buffer;
2168 const gchar *cur_encoding;
2169 gchar buf[BUFFSIZE];
2172 gboolean badtxt = FALSE;
2174 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2176 if ((fp = fopen(file, "rb")) == NULL) {
2177 FILE_OP_ERROR(file, "fopen");
2178 return COMPOSE_INSERT_READ_ERROR;
2181 text = GTK_TEXT_VIEW(compose->text);
2182 buffer = gtk_text_view_get_buffer(text);
2183 mark = gtk_text_buffer_get_insert(buffer);
2184 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2186 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2187 G_CALLBACK(text_inserted),
2190 cur_encoding = conv_get_locale_charset_str();
2192 while (fgets(buf, sizeof(buf), fp) != NULL) {
2195 str = conv_codeset_strdup(buf, cur_encoding, CS_INTERNAL);
2198 /* strip <CR> if DOS/Windows file,
2199 replace <CR> with <LF> if Macintosh file. */
2202 if (len > 0 && str[len - 1] != '\n') {
2204 if (str[len] == '\r') str[len] = '\n';
2207 gtk_text_buffer_insert(buffer, &iter, str, -1);
2211 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2212 G_CALLBACK(text_inserted),
2218 return COMPOSE_INSERT_INVALID_CHARACTER;
2220 return COMPOSE_INSERT_SUCCESS;
2223 static void compose_attach_append(Compose *compose, const gchar *file,
2224 const gchar *filename,
2225 const gchar *content_type)
2233 GtkListStore *store;
2236 if (!is_file_exist(file)) {
2237 g_warning("File %s doesn't exist\n", file);
2240 if ((size = get_file_size(file)) < 0) {
2241 g_warning("Can't get file size of %s\n", file);
2245 alertpanel_notice(_("File %s is empty."), file);
2248 if ((fp = fopen(file, "rb")) == NULL) {
2249 alertpanel_error(_("Can't read %s."), file);
2254 #if 0 /* NEW COMPOSE GUI */
2255 if (!compose->use_attach) {
2256 GtkItemFactory *ifactory;
2258 ifactory = gtk_item_factory_from_widget(compose->menubar);
2259 menu_set_active(ifactory, "/View/Attachment", TRUE);
2262 ainfo = g_new0(AttachInfo, 1);
2263 auto_ainfo = g_auto_pointer_new_with_free
2264 (ainfo, (GFreeFunc) compose_attach_info_free);
2265 ainfo->file = g_strdup(file);
2268 ainfo->content_type = g_strdup(content_type);
2269 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2271 MsgFlags flags = {0, 0};
2273 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2274 ainfo->encoding = ENC_7BIT;
2276 ainfo->encoding = ENC_8BIT;
2278 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2279 if (msginfo && msginfo->subject)
2280 name = g_strdup(msginfo->subject);
2282 name = g_path_get_basename(filename ? filename : file);
2284 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2286 procmsg_msginfo_free(msginfo);
2288 if (!g_ascii_strncasecmp(content_type, "text", 4))
2289 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2291 ainfo->encoding = ENC_BASE64;
2292 name = g_path_get_basename(filename ? filename : file);
2293 ainfo->name = g_strdup(name);
2297 ainfo->content_type = procmime_get_mime_type(file);
2298 if (!ainfo->content_type) {
2299 ainfo->content_type =
2300 g_strdup("application/octet-stream");
2301 ainfo->encoding = ENC_BASE64;
2302 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2304 procmime_get_encoding_for_text_file(file);
2306 ainfo->encoding = ENC_BASE64;
2307 name = g_path_get_basename(filename ? filename : file);
2308 ainfo->name = g_strdup(name);
2312 if (!strcmp(ainfo->content_type, "unknown")) {
2313 g_free(ainfo->content_type);
2314 ainfo->content_type = g_strdup("application/octet-stream");
2318 size_text = to_human_readable(size);
2320 store = GTK_LIST_STORE(gtk_tree_view_get_model
2321 (GTK_TREE_VIEW(compose->attach_clist)));
2323 gtk_list_store_append(store, &iter);
2324 gtk_list_store_set(store, &iter,
2325 COL_MIMETYPE, ainfo->content_type,
2326 COL_SIZE, size_text,
2327 COL_NAME, ainfo->name,
2329 COL_AUTODATA, auto_ainfo,
2332 g_auto_pointer_free(auto_ainfo);
2335 static void compose_use_signing(Compose *compose, gboolean use_signing)
2337 GtkItemFactory *ifactory;
2338 GtkWidget *menuitem = NULL;
2340 compose->use_signing = use_signing;
2341 ifactory = gtk_item_factory_from_widget(compose->menubar);
2342 menuitem = gtk_item_factory_get_item
2343 (ifactory, "/Options/Sign");
2344 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2348 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2350 GtkItemFactory *ifactory;
2351 GtkWidget *menuitem = NULL;
2353 compose->use_encryption = use_encryption;
2354 ifactory = gtk_item_factory_from_widget(compose->menubar);
2355 menuitem = gtk_item_factory_get_item
2356 (ifactory, "/Options/Encrypt");
2358 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2362 #define NEXT_PART_NOT_CHILD(info) \
2364 node = info->node; \
2365 while (node->children) \
2366 node = g_node_last_child(node); \
2367 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2370 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2374 MimeInfo *firsttext = NULL;
2375 MimeInfo *encrypted = NULL;
2378 const gchar *partname = NULL;
2380 mimeinfo = procmime_scan_message(msginfo);
2381 if (!mimeinfo) return;
2383 if (mimeinfo->node->children == NULL) {
2384 procmime_mimeinfo_free_all(mimeinfo);
2388 /* find first content part */
2389 child = (MimeInfo *) mimeinfo->node->children->data;
2390 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2391 child = (MimeInfo *)child->node->children->data;
2393 if (child->type == MIMETYPE_TEXT) {
2395 debug_print("First text part found\n");
2396 } else if (compose->mode == COMPOSE_REEDIT &&
2397 child->type == MIMETYPE_APPLICATION &&
2398 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2400 val = alertpanel(_("Encrypted message"),
2401 _("Cannot re-edit an encrypted message. \n"
2402 "Discard encrypted part?"),
2403 _("Yes"), _("No"), NULL);
2404 if (val == G_ALERTDEFAULT)
2405 encrypted = (MimeInfo *)child->node->parent->data;
2408 child = (MimeInfo *) mimeinfo->node->children->data;
2409 while (child != NULL) {
2410 if (child == encrypted) {
2411 /* skip this part of tree */
2412 NEXT_PART_NOT_CHILD(child);
2416 if (child->type == MIMETYPE_MULTIPART) {
2417 /* get the actual content */
2418 child = procmime_mimeinfo_next(child);
2422 if (child == firsttext) {
2423 child = procmime_mimeinfo_next(child);
2427 outfile = procmime_get_tmp_file_name(child);
2428 if (procmime_get_part(outfile, child) < 0)
2429 g_warning("Can't get the part of multipart message.");
2431 gchar *content_type;
2433 content_type = procmime_get_content_type_str(child->type, child->subtype);
2434 partname = procmime_mimeinfo_get_parameter(child, "name");
2435 if (partname == NULL)
2437 compose_attach_append(compose, outfile,
2438 partname, content_type);
2439 g_free(content_type);
2442 NEXT_PART_NOT_CHILD(child);
2444 procmime_mimeinfo_free_all(mimeinfo);
2447 #undef NEXT_PART_NOT_CHILD
2452 WAIT_FOR_INDENT_CHAR,
2453 WAIT_FOR_INDENT_CHAR_OR_SPACE,
2456 /* return indent length, we allow:
2457 indent characters followed by indent characters or spaces/tabs,
2458 alphabets and numbers immediately followed by indent characters,
2459 and the repeating sequences of the above
2460 If quote ends with multiple spaces, only the first one is included. */
2461 static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
2462 const GtkTextIter *start, gint *len)
2464 GtkTextIter iter = *start;
2468 IndentState state = WAIT_FOR_INDENT_CHAR;
2471 gint alnum_count = 0;
2472 gint space_count = 0;
2475 if (prefs_common.quote_chars == NULL) {
2479 while (!gtk_text_iter_ends_line(&iter)) {
2480 wc = gtk_text_iter_get_char(&iter);
2481 if (g_unichar_iswide(wc))
2483 clen = g_unichar_to_utf8(wc, ch);
2487 is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
2488 is_space = g_unichar_isspace(wc);
2490 if (state == WAIT_FOR_INDENT_CHAR) {
2491 if (!is_indent && !g_unichar_isalnum(wc))
2494 quote_len += alnum_count + space_count + 1;
2495 alnum_count = space_count = 0;
2496 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2499 } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
2500 if (!is_indent && !is_space && !g_unichar_isalnum(wc))
2504 else if (is_indent) {
2505 quote_len += alnum_count + space_count + 1;
2506 alnum_count = space_count = 0;
2509 state = WAIT_FOR_INDENT_CHAR;
2513 gtk_text_iter_forward_char(&iter);
2516 if (quote_len > 0 && space_count > 0)
2522 if (quote_len > 0) {
2524 gtk_text_iter_forward_chars(&iter, quote_len);
2525 return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
2531 static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
2532 const GtkTextIter *start,
2533 GtkTextIter *break_pos,
2537 GtkTextIter iter = *start, line_end = *start;
2538 PangoLogAttr *attrs;
2545 gboolean can_break = FALSE;
2546 gboolean do_break = FALSE;
2548 gtk_text_iter_forward_to_line_end(&line_end);
2549 str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
2550 len = g_utf8_strlen(str, -1);
2551 /* g_print("breaking line: %d: %s (len = %d)\n",
2552 gtk_text_iter_get_line(&iter), str, len); */
2553 attrs = g_new(PangoLogAttr, len + 1);
2555 pango_default_break(str, -1, NULL, attrs, len + 1);
2559 /* skip quote and leading spaces */
2560 for (i = 0; *p != '\0' && i < len; i++) {
2563 wc = g_utf8_get_char(p);
2564 if (i >= quote_len && !g_unichar_isspace(wc))
2566 col += g_unichar_iswide(wc) ? 2 : 1;
2567 p = g_utf8_next_char(p);
2570 for (; *p != '\0' && i < len; i++) {
2571 PangoLogAttr *attr = attrs + i;
2575 if (attr->is_line_break && can_break)
2578 /* don't wrap URI */
2579 if ((uri_len = get_uri_len(p)) > 0) {
2581 if (pos > 0 && col > max_col) {
2591 wc = g_utf8_get_char(p);
2592 col += g_unichar_iswide(wc) ? 2 : 1;
2593 if (pos > 0 && col > max_col) {
2598 p = g_utf8_next_char(p);
2602 debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
2607 *break_pos = *start;
2608 gtk_text_iter_set_line_offset(break_pos, pos);
2613 static gboolean is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, guint start_pos)
2617 GtkTextIter end_iter;
2618 if (!compose->account->sig_sep)
2621 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, start_pos+1);
2622 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
2623 start_pos+strlen(compose->account->sig_sep)+1);
2625 if (!strcmp(gtk_text_iter_get_text(&iter, &end_iter),
2626 compose->account->sig_sep)) {
2628 gtk_text_buffer_get_iter_at_offset(textbuf, &iter,
2629 start_pos+strlen(compose->account->sig_sep)+1);
2630 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
2631 start_pos+strlen(compose->account->sig_sep)+2);
2633 if (!strcmp(gtk_text_iter_get_text(&iter, &end_iter),"\n"));
2642 static gboolean compose_join_next_line(GtkTextBuffer *buffer,
2644 const gchar *quote_str)
2646 GtkTextIter iter_ = *iter, cur, prev, next;
2647 PangoLogAttr attrs[3];
2649 gchar *next_quote_str;
2653 if (!gtk_text_iter_forward_line(&iter_) ||
2654 gtk_text_iter_ends_line(&iter_))
2657 next_quote_str = compose_get_quote_str(buffer, &iter_, "e_len);
2659 if ((quote_str || next_quote_str) &&
2660 strcmp2(quote_str, next_quote_str) != 0) {
2661 g_free(next_quote_str);
2664 g_free(next_quote_str);
2666 /* delete quote str */
2667 if (quote_len > 0) {
2668 GtkTextIter end = iter_;
2670 gtk_text_iter_forward_chars(&end, quote_len);
2671 if (gtk_text_iter_ends_line(&end))
2673 gtk_text_buffer_delete(buffer, &iter_, &end);
2676 /* delete linebreak and extra spaces */
2678 while (gtk_text_iter_backward_char(&cur)) {
2679 wc1 = gtk_text_iter_get_char(&cur);
2680 if (!g_unichar_isspace(wc1))
2685 while (!gtk_text_iter_ends_line(&cur)) {
2686 wc1 = gtk_text_iter_get_char(&cur);
2687 if (!g_unichar_isspace(wc1))
2689 gtk_text_iter_forward_char(&cur);
2692 if (!gtk_text_iter_equal(&prev, &next))
2693 gtk_text_buffer_delete(buffer, &prev, &next);
2696 /* insert space if required */
2697 gtk_text_iter_backward_char(&prev);
2698 wc1 = gtk_text_iter_get_char(&prev);
2699 wc2 = gtk_text_iter_get_char(&next);
2700 gtk_text_iter_forward_char(&next);
2701 str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
2702 pango_default_break(str, -1, NULL, attrs, 3);
2703 if (!attrs[1].is_line_break ||
2704 (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2)))
2705 gtk_text_buffer_insert(buffer, &iter_, " ", 1);
2712 static void compose_wrap_paragraph(Compose *compose, GtkTextIter *par_iter)
2714 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2715 GtkTextBuffer *buffer;
2716 GtkTextIter iter, break_pos;
2717 gchar *quote_str = NULL;
2719 gboolean wrap_quote = prefs_common.linewrap_quote;
2721 buffer = gtk_text_view_get_buffer(text);
2727 mark = gtk_text_buffer_get_insert(buffer);
2728 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2731 /* move to paragraph start */
2732 gtk_text_iter_set_line_offset(&iter, 0);
2733 if (gtk_text_iter_ends_line(&iter)) {
2734 while (gtk_text_iter_ends_line(&iter) &&
2735 gtk_text_iter_forward_line(&iter))
2738 while (gtk_text_iter_backward_line(&iter)) {
2739 if (gtk_text_iter_ends_line(&iter)) {
2740 gtk_text_iter_forward_line(&iter);
2746 if (gtk_text_iter_is_end(&iter)) {
2753 quote_str = compose_get_quote_str(buffer, &iter, "e_len);
2756 gtk_text_iter_forward_line(&iter);
2760 debug_print("compose_wrap_paragraph(): quote_str = '%s'\n", quote_str);
2763 if (compose_get_line_break_pos(buffer, &iter, &break_pos,
2764 prefs_common.linewrap_len,
2766 gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
2768 gtk_text_buffer_insert(buffer, &break_pos,
2772 compose_join_next_line(buffer, &iter, quote_str);
2774 /* move iter to current line start */
2775 gtk_text_iter_set_line_offset(&iter, 0);
2777 /* move iter to next line start */
2779 gtk_text_iter_forward_line(&iter);
2783 } while (!gtk_text_iter_ends_line(&iter));
2784 /* stop if paragraph end (empty line) */
2790 static void compose_wrap_all(Compose *compose)
2792 compose_wrap_all_full(compose, FALSE);
2795 static void compose_wrap_all_full(Compose *compose, gboolean autowrap)
2797 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2798 GtkTextBuffer *buffer;
2801 buffer = gtk_text_view_get_buffer(text);
2803 gtk_text_buffer_get_start_iter(buffer, &iter);
2804 while (!gtk_text_iter_is_end(&iter))
2805 compose_wrap_paragraph(compose, &iter);
2808 static void compose_set_title(Compose *compose)
2813 edited = compose->modified ? _(" [Edited]") : "";
2814 if (compose->account && compose->account->address)
2815 str = g_strdup_printf(_("%s - Compose message%s"),
2816 compose->account->address, edited);
2818 str = g_strdup_printf(_("Compose message%s"), edited);
2819 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2824 * compose_current_mail_account:
2826 * Find a current mail account (the currently selected account, or the
2827 * default account, if a news account is currently selected). If a
2828 * mail account cannot be found, display an error message.
2830 * Return value: Mail account, or NULL if not found.
2832 static PrefsAccount *
2833 compose_current_mail_account(void)
2837 if (cur_account && cur_account->protocol != A_NNTP)
2840 ac = account_get_default();
2841 if (!ac || ac->protocol == A_NNTP) {
2842 alertpanel_error(_("Account for sending mail is not specified.\n"
2843 "Please select a mail account before sending."));
2850 static void compose_select_account(Compose *compose, PrefsAccount *account,
2853 GtkItemFactory *ifactory;
2855 g_return_if_fail(account != NULL);
2857 compose->account = account;
2859 compose_set_title(compose);
2861 ifactory = gtk_item_factory_from_widget(compose->menubar);
2863 if (account->protocol == A_NNTP) {
2864 gtk_widget_show(compose->newsgroups_hbox);
2865 gtk_widget_show(compose->newsgroups_entry);
2866 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
2867 compose->use_newsgroups = TRUE;
2869 menu_set_active(ifactory, "/View/To", FALSE);
2870 menu_set_sensitive(ifactory, "/View/To", TRUE);
2871 menu_set_active(ifactory, "/View/Cc", FALSE);
2872 menu_set_sensitive(ifactory, "/View/Cc", TRUE);
2873 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
2875 gtk_widget_hide(compose->newsgroups_hbox);
2876 gtk_widget_hide(compose->newsgroups_entry);
2877 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
2878 gtk_widget_queue_resize(compose->table_vbox);
2879 compose->use_newsgroups = FALSE;
2881 menu_set_active(ifactory, "/View/To", TRUE);
2882 menu_set_sensitive(ifactory, "/View/To", FALSE);
2883 menu_set_active(ifactory, "/View/Cc", TRUE);
2884 menu_set_sensitive(ifactory, "/View/Cc", FALSE);
2885 menu_set_active(ifactory, "/View/Followup to", FALSE);
2886 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
2889 if (account->set_autocc) {
2890 compose_entry_show(compose, COMPOSE_ENTRY_CC);
2891 if (account->auto_cc && compose->mode != COMPOSE_REEDIT)
2892 compose_entry_set(compose, account->auto_cc,
2895 if (account->set_autobcc) {
2896 compose_entry_show(compose, COMPOSE_ENTRY_BCC);
2897 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
2898 compose_entry_set(compose, account->auto_bcc,
2901 if (account->set_autoreplyto) {
2902 compose_entry_show(compose, COMPOSE_ENTRY_REPLY_TO);
2903 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
2904 compose_entry_set(compose, account->auto_replyto,
2905 COMPOSE_ENTRY_REPLY_TO);
2910 if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
2911 menu_set_active(ifactory, "/Options/Sign", TRUE);
2913 menu_set_active(ifactory, "/Options/Sign", FALSE);
2914 if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
2915 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
2917 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
2919 activate_privacy_system(compose, account);
2921 if (!init && compose->mode != COMPOSE_REDIRECT)
2922 compose_insert_sig(compose, TRUE);
2925 gboolean compose_check_for_valid_recipient(Compose *compose) {
2926 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2927 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2928 gboolean recipient_found = FALSE;
2932 /* free to and newsgroup list */
2933 slist_free_strings(compose->to_list);
2934 g_slist_free(compose->to_list);
2935 compose->to_list = NULL;
2937 slist_free_strings(compose->newsgroup_list);
2938 g_slist_free(compose->newsgroup_list);
2939 compose->newsgroup_list = NULL;
2941 /* search header entries for to and newsgroup entries */
2942 for (list = compose->header_list; list; list = list->next) {
2945 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
2946 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2948 if (entry[0] != '\0') {
2949 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2950 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2951 compose->to_list = address_list_append(compose->to_list, entry);
2952 recipient_found = TRUE;
2955 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2956 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2957 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2958 recipient_found = TRUE;
2965 return recipient_found;
2968 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
2972 if (compose_check_for_valid_recipient(compose) == FALSE) {
2973 alertpanel_error(_("Recipient is not specified."));
2977 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2978 if (*str == '\0' && check_subject == TRUE) {
2981 aval = alertpanel(_("Send"),
2982 _("Subject is empty. Send it anyway?"),
2983 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
2984 if (aval != G_ALERTDEFAULT)
2991 gint compose_send(Compose *compose)
2998 compose_allow_user_actions (compose, FALSE);
2999 compose->sending = TRUE;
3001 if (compose_check_entries(compose, TRUE) == FALSE)
3004 val = compose_queue(compose, &msgnum, &folder);
3007 alertpanel_error(_("Could not queue message for sending"));
3012 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3013 compose->sending = FALSE;
3014 compose_close(compose);
3015 /* No more compose access in the normal codepath
3016 * after this point! */
3020 alertpanel_error(_("The message was queued but could not be "
3021 "sent.\nUse \"Send queued messages\" from "
3022 "the main window to retry."));
3023 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3024 compose->sending = FALSE;
3025 compose_allow_user_actions (compose, TRUE);
3030 msgpath = folder_item_fetch_msg(folder, msgnum);
3031 val = procmsg_send_message_queue(msgpath);
3034 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3035 compose->sending = FALSE;
3036 compose_allow_user_actions (compose, TRUE);
3038 folder_item_remove_msg(folder, msgnum);
3039 folder_item_scan(folder);
3044 folder_item_remove_msg(folder, msgnum);
3045 folder_item_scan(folder);
3046 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3047 compose_close(compose);
3049 alertpanel_error(_("The message was queued but could not be "
3050 "sent.\nUse \"Send queued messages\" from "
3051 "the main window to retry."));
3052 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3053 compose_allow_user_actions (compose, TRUE);
3054 compose->sending = FALSE;
3062 compose_allow_user_actions (compose, TRUE);
3063 compose->sending = FALSE;
3068 static gboolean compose_use_attach(Compose *compose)
3070 GtkTreeModel *model = gtk_tree_view_get_model
3071 (GTK_TREE_VIEW(compose->attach_clist));
3072 return gtk_tree_model_iter_n_children(model, NULL) > 0;
3075 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3078 gchar buf[BUFFSIZE];
3080 gboolean first_to_address;
3081 gboolean first_cc_address;
3083 ComposeHeaderEntry *headerentry;
3084 const gchar *headerentryname;
3088 debug_print("Writing redirect header\n");
3090 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3091 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3093 first_to_address = TRUE;
3094 first_cc_address = TRUE;
3095 for (list = compose->header_list; list; list = list->next) {
3096 headerentry = ((ComposeHeaderEntry *)list->data);
3097 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3099 if (g_utf8_collate(headerentryname, cc_hdr) == 0
3100 || g_utf8_collate(headerentryname, to_hdr) == 0) {
3101 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3102 Xstrdup_a(str, entstr, return -1);
3104 if (str[0] != '\0') {
3105 compose_convert_header
3106 (buf, sizeof(buf), str,
3107 strlen("Resent-To") + 2, TRUE);
3108 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3109 if (first_to_address) {
3110 fprintf(fp, "Resent-To: ");
3111 first_to_address = FALSE;
3116 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
3117 if (first_cc_address) {
3119 fprintf(fp, "Resent-Cc: ");
3120 first_cc_address = FALSE;
3126 fprintf(fp, "%s", buf);
3130 /* if (!first_address) { */
3137 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3139 gchar buf[BUFFSIZE];
3141 const gchar *entstr;
3142 /* struct utsname utsbuf; */
3144 g_return_val_if_fail(fp != NULL, -1);
3145 g_return_val_if_fail(compose->account != NULL, -1);
3146 g_return_val_if_fail(compose->account->address != NULL, -1);
3149 get_rfc822_date(buf, sizeof(buf));
3150 fprintf(fp, "Resent-Date: %s\n", buf);
3153 if (compose->account->name && *compose->account->name) {
3154 compose_convert_header
3155 (buf, sizeof(buf), compose->account->name,
3156 strlen("From: "), TRUE);
3157 fprintf(fp, "Resent-From: %s <%s>\n",
3158 buf, compose->account->address);
3160 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3163 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3164 if (*entstr != '\0') {
3165 Xstrdup_a(str, entstr, return -1);
3168 compose_convert_header(buf, sizeof(buf), str,
3169 strlen("Subject: "), FALSE);
3170 fprintf(fp, "Subject: %s\n", buf);
3174 /* Resent-Message-ID */
3175 if (compose->account->gen_msgid) {
3176 generate_msgid(buf, sizeof(buf));
3177 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3178 compose->msgid = g_strdup(buf);
3181 compose_redirect_write_headers_from_headerlist(compose, fp);
3183 /* separator between header and body */
3189 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3193 gchar buf[BUFFSIZE];
3195 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
3196 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3200 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3201 /* should filter returnpath, delivered-to */
3202 if (g_ascii_strncasecmp(buf, "Return-Path:",
3203 strlen("Return-Path:")) == 0 ||
3204 g_ascii_strncasecmp(buf, "Delivered-To:",
3205 strlen("Delivered-To:")) == 0 ||
3206 g_ascii_strncasecmp(buf, "Received:",
3207 strlen("Received:")) == 0 ||
3208 g_ascii_strncasecmp(buf, "Subject:",
3209 strlen("Subject:")) == 0 ||
3210 g_ascii_strncasecmp(buf, "X-UIDL:",
3211 strlen("X-UIDL:")) == 0)
3214 if (fputs(buf, fdest) == -1)
3217 if (!prefs_common.redirect_keep_from) {
3218 if (g_ascii_strncasecmp(buf, "From:",
3219 strlen("From:")) == 0) {
3220 fputs(" (by way of ", fdest);
3221 if (compose->account->name
3222 && *compose->account->name) {
3223 compose_convert_header
3225 compose->account->name,
3228 fprintf(fdest, "%s <%s>",
3230 compose->account->address);
3232 fprintf(fdest, "%s",
3233 compose->account->address);
3238 if (fputs("\n", fdest) == -1)
3242 compose_redirect_write_headers(compose, fdest);
3244 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3245 if (fwrite(buf, sizeof(gchar), len, fdest) != len)