2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2004 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/gtktreeview.h>
52 #include <gtk/gtkdnd.h>
57 #include <sys/types.h>
61 /* #include <sys/utsname.h> */
68 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
75 #include "mainwindow.h"
77 #include "addressbook.h"
78 #include "folderview.h"
81 #include "stock_pixmap.h"
82 #include "send_message.h"
85 #include "customheader.h"
86 #include "prefs_common.h"
87 #include "prefs_account.h"
91 #include "procheader.h"
93 #include "statusbar.h"
96 #include "quoted-printable.h"
101 #include "alertpanel.h"
102 #include "manage_window.h"
103 #include "gtkshruler.h"
105 #include "addr_compl.h"
106 #include "quote_fmt.h"
107 #include "template.h"
109 #include "foldersel.h"
119 #define N_ATTACH_COLS 3
123 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
124 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
125 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
126 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
127 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
128 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
129 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
130 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
131 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
132 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
133 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
134 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
135 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
136 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
137 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
138 } ComposeCallAdvancedAction;
142 PRIORITY_HIGHEST = 1,
151 COMPOSE_INSERT_SUCCESS,
152 COMPOSE_INSERT_READ_ERROR,
153 COMPOSE_INSERT_INVALID_CHARACTER,
154 COMPOSE_INSERT_NO_FILE
155 } ComposeInsertResult;
159 COMPOSE_QUIT_EDITING,
160 COMPOSE_KEEP_EDITING,
162 } ComposeDraftAction;
166 COMPOSE_WRITE_FOR_SEND,
167 COMPOSE_WRITE_FOR_STORE
170 #define B64_LINE_SIZE 57
171 #define B64_BUFFSIZE 77
173 #define MAX_REFERENCES_LEN 999
175 static GdkColor quote_color = {0, 0, 0, 0xbfff};
177 static GList *compose_list = NULL;
179 Compose *compose_generic_new (PrefsAccount *account,
182 GPtrArray *attach_files,
183 GList *listAddress );
185 static Compose *compose_create (PrefsAccount *account,
188 static GtkWidget *compose_account_option_menu_create
190 static void compose_set_template_menu (Compose *compose);
191 static void compose_template_apply (Compose *compose,
194 static void compose_destroy (Compose *compose);
196 static void compose_entries_set (Compose *compose,
197 const gchar *mailto);
198 static gint compose_parse_header (Compose *compose,
200 static gchar *compose_parse_references (const gchar *ref,
203 static gchar *compose_quote_fmt (Compose *compose,
209 static void compose_reply_set_entry (Compose *compose,
215 followup_and_reply_to);
216 static void compose_reedit_set_entry (Compose *compose,
218 static void compose_insert_sig (Compose *compose,
220 static gchar *compose_get_signature_str (Compose *compose);
221 static ComposeInsertResult compose_insert_file (Compose *compose,
223 static void compose_attach_append (Compose *compose,
226 const gchar *content_type);
227 static void compose_attach_parts (Compose *compose,
229 static void compose_wrap_line (Compose *compose);
230 static void compose_wrap_line_all (Compose *compose);
231 static void compose_wrap_line_all_full (Compose *compose,
233 static void compose_set_title (Compose *compose);
234 static void compose_select_account (Compose *compose,
235 PrefsAccount *account,
238 static PrefsAccount *compose_current_mail_account(void);
239 /* static gint compose_send (Compose *compose); */
240 static gboolean compose_check_for_valid_recipient
242 static gboolean compose_check_entries (Compose *compose,
243 gboolean check_subject);
244 static gint compose_write_to_file (Compose *compose,
247 static gint compose_write_body_to_file (Compose *compose,
249 static gint compose_remove_reedit_target (Compose *compose);
250 void compose_remove_draft (Compose *compose);
251 static gint compose_queue (Compose *compose,
254 static gint compose_queue_sub (Compose *compose,
257 gboolean check_subject);
258 static void compose_add_attachments (Compose *compose,
260 static gchar *compose_get_header (Compose *compose);
262 static void compose_convert_header (gchar *dest,
266 gboolean addr_field);
268 static void compose_attach_info_free (AttachInfo *ainfo);
269 static void compose_attach_remove_selected (Compose *compose);
271 static void compose_attach_property (Compose *compose);
272 static void compose_attach_property_create (gboolean *cancelled);
273 static void attach_property_ok (GtkWidget *widget,
274 gboolean *cancelled);
275 static void attach_property_cancel (GtkWidget *widget,
276 gboolean *cancelled);
277 static gint attach_property_delete_event (GtkWidget *widget,
279 gboolean *cancelled);
280 static gboolean attach_property_key_pressed (GtkWidget *widget,
282 gboolean *cancelled);
284 static void compose_exec_ext_editor (Compose *compose);
285 static gint compose_exec_ext_editor_real (const gchar *file);
286 static gboolean compose_ext_editor_kill (Compose *compose);
287 static void compose_input_cb (gpointer data,
289 GdkInputCondition condition);
290 static void compose_set_ext_editor_sensitive (Compose *compose,
293 static void compose_undo_state_changed (UndoMain *undostruct,
298 static gint calc_cursor_xpos (GtkTextView *text,
302 static void compose_create_header_entry (Compose *compose);
303 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
304 static void compose_update_priority_menu_item(Compose * compose);
306 static void compose_add_field_list ( Compose *compose,
307 GList *listAddress );
309 /* callback functions */
311 static gboolean compose_edit_size_alloc (GtkEditable *widget,
312 GtkAllocation *allocation,
313 GtkSHRuler *shruler);
314 static void account_activated (GtkMenuItem *menuitem,
316 static void attach_selected (GtkCList *clist,
321 static gboolean attach_button_pressed (GtkWidget *widget,
322 GdkEventButton *event,
324 static gboolean attach_key_pressed (GtkWidget *widget,
328 static void compose_send_cb (gpointer data,
331 static void compose_send_later_cb (gpointer data,
335 static void compose_draft_cb (gpointer data,
339 static void compose_attach_cb (gpointer data,
342 static void compose_insert_file_cb (gpointer data,
345 static void compose_insert_sig_cb (gpointer data,
349 static void compose_close_cb (gpointer data,
353 static void compose_address_cb (gpointer data,
356 static void compose_template_activate_cb(GtkWidget *widget,
359 static void compose_ext_editor_cb (gpointer data,
363 static gint compose_delete_cb (GtkWidget *widget,
366 static void compose_destroy_cb (GtkWidget *widget,
369 static void compose_undo_cb (Compose *compose);
370 static void compose_redo_cb (Compose *compose);
371 static void compose_cut_cb (Compose *compose);
372 static void compose_copy_cb (Compose *compose);
373 static void compose_paste_cb (Compose *compose);
374 static void compose_paste_as_quote_cb (Compose *compose);
375 static void compose_allsel_cb (Compose *compose);
377 static void compose_advanced_action_cb (Compose *compose,
378 ComposeCallAdvancedAction action);
380 static void compose_grab_focus_cb (GtkWidget *widget,
382 static void compose_grab_focus_before_cb(GtkWidget *widget,
385 static void compose_changed_cb (GtkTextBuffer *textbuf,
388 static void compose_toggle_autowrap_cb (gpointer data,
393 static void compose_toggle_to_cb (gpointer data,
396 static void compose_toggle_cc_cb (gpointer data,
399 static void compose_toggle_bcc_cb (gpointer data,
402 static void compose_toggle_replyto_cb (gpointer data,
405 static void compose_toggle_followupto_cb(gpointer data,
408 static void compose_toggle_attach_cb (gpointer data,
412 static void compose_toggle_ruler_cb (gpointer data,
415 static void compose_toggle_sign_cb (gpointer data,
418 static void compose_toggle_encrypt_cb (gpointer data,
421 static void compose_set_privacy_system_cb(gpointer data,
424 static void compose_update_privacy_system_menu_item(Compose * compose);
425 static void activate_privacy_system (Compose *compose,
426 PrefsAccount *account);
427 static void compose_use_signing(Compose *compose, gboolean use_signing);
428 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
429 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
431 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
433 static void compose_set_priority_cb (gpointer data,
437 static void compose_attach_drag_received_cb (GtkWidget *widget,
438 GdkDragContext *drag_context,
441 GtkSelectionData *data,
445 static void compose_insert_drag_received_cb (GtkWidget *widget,
446 GdkDragContext *drag_context,
449 GtkSelectionData *data,
455 static void to_activated (GtkWidget *widget,
457 static void newsgroups_activated (GtkWidget *widget,
459 static void cc_activated (GtkWidget *widget,
461 static void bcc_activated (GtkWidget *widget,
463 static void replyto_activated (GtkWidget *widget,
465 static void followupto_activated (GtkWidget *widget,
467 static void subject_activated (GtkWidget *widget,
471 static void text_activated (GtkWidget *widget,
473 static void text_inserted (GtkTextBuffer *buffer,
478 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
479 gboolean to_all, gboolean to_ml,
481 gboolean followup_and_reply_to,
484 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
485 ComposeHeaderEntry *headerentry);
486 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
488 ComposeHeaderEntry *headerentry);
490 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
492 static void compose_allow_user_actions (Compose *compose, gboolean allow);
495 static void compose_check_all (Compose *compose);
496 static void compose_highlight_all (Compose *compose);
497 static void compose_check_backwards (Compose *compose);
498 static void compose_check_forwards_go (Compose *compose);
501 static gboolean compose_send_control_enter (Compose *compose);
502 static gint compose_defer_auto_save_draft (Compose *compose);
503 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
505 static GtkItemFactoryEntry compose_popup_entries[] =
507 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
508 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
509 {N_("/---"), NULL, NULL, 0, "<Separator>"},
510 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
513 static GtkItemFactoryEntry compose_entries[] =
515 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
516 {N_("/_Message/_Send"), "<control>Return",
517 compose_send_cb, 0, NULL},
518 {N_("/_Message/Send _later"), "<shift><control>S",
519 compose_send_later_cb, 0, NULL},
520 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
521 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
522 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
523 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
524 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
525 {N_("/_Message/_Save"),
526 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
527 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
528 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
530 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
531 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
532 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
533 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
534 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
535 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
536 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
537 {N_("/_Edit/Paste as _quotation"),
538 NULL, compose_paste_as_quote_cb, 0, NULL},
539 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
540 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
541 {N_("/_Edit/A_dvanced/Move a character backward"),
543 compose_advanced_action_cb,
544 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
546 {N_("/_Edit/A_dvanced/Move a character forward"),
548 compose_advanced_action_cb,
549 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
551 {N_("/_Edit/A_dvanced/Move a word backward"),
553 compose_advanced_action_cb,
554 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
556 {N_("/_Edit/A_dvanced/Move a word forward"),
558 compose_advanced_action_cb,
559 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
561 {N_("/_Edit/A_dvanced/Move to beginning of line"),
562 NULL, /* "<control>A" */
563 compose_advanced_action_cb,
564 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
566 {N_("/_Edit/A_dvanced/Move to end of line"),
568 compose_advanced_action_cb,
569 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
571 {N_("/_Edit/A_dvanced/Move to previous line"),
573 compose_advanced_action_cb,
574 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
576 {N_("/_Edit/A_dvanced/Move to next line"),
578 compose_advanced_action_cb,
579 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
581 {N_("/_Edit/A_dvanced/Delete a character backward"),
583 compose_advanced_action_cb,
584 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
586 {N_("/_Edit/A_dvanced/Delete a character forward"),
588 compose_advanced_action_cb,
589 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
591 {N_("/_Edit/A_dvanced/Delete a word backward"),
592 NULL, /* "<control>W" */
593 compose_advanced_action_cb,
594 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
596 {N_("/_Edit/A_dvanced/Delete a word forward"),
597 NULL, /* "<alt>D", */
598 compose_advanced_action_cb,
599 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
601 {N_("/_Edit/A_dvanced/Delete line"),
603 compose_advanced_action_cb,
604 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
606 {N_("/_Edit/A_dvanced/Delete entire line"),
608 compose_advanced_action_cb,
609 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
611 {N_("/_Edit/A_dvanced/Delete to end of line"),
613 compose_advanced_action_cb,
614 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
616 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
617 {N_("/_Edit/_Wrap current paragraph"),
618 "<control>L", compose_wrap_line, 0, NULL},
619 {N_("/_Edit/Wrap all long _lines"),
620 "<control><alt>L", compose_wrap_line_all, 0, NULL},
621 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
622 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
623 {N_("/_Edit/Edit with e_xternal editor"),
624 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
626 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
627 {N_("/_Spelling/_Check all or check selection"),
628 NULL, compose_check_all, 0, NULL},
629 {N_("/_Spelling/_Highlight all misspelled words"),
630 NULL, compose_highlight_all, 0, NULL},
631 {N_("/_Spelling/Check _backwards misspelled word"),
632 NULL, compose_check_backwards , 0, NULL},
633 {N_("/_Spelling/_Forward to next misspelled word"),
634 NULL, compose_check_forwards_go, 0, NULL},
635 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
636 {N_("/_Spelling/_Spelling Configuration"),
637 NULL, NULL, 0, "<Branch>"},
639 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
640 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
641 {N_("/_Options/Privacy System/None"), NULL, compose_set_privacy_system_cb, 0, "<RadioItem>"},
642 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
643 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
644 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
645 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
646 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
647 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
648 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
649 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
650 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
651 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
652 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
653 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
654 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
655 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
656 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
657 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
658 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
659 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
660 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
663 static GtkTargetEntry compose_mime_types[] =
665 {"text/uri-list", 0, 0}
668 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
669 GPtrArray *attach_files)
671 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
674 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
676 return compose_generic_new(account, NULL, item, NULL, NULL);
679 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
681 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
684 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
685 GPtrArray *attach_files, GList *listAddress )
688 GtkTextView *textview;
689 GtkTextBuffer *textbuf;
691 GtkItemFactory *ifactory;
693 if (item && item->prefs && item->prefs->enable_default_account)
694 account = account_find_from_id(item->prefs->default_account);
696 if (!account) account = cur_account;
697 g_return_val_if_fail(account != NULL, NULL);
699 compose = compose_create(account, COMPOSE_NEW);
700 ifactory = gtk_item_factory_from_widget(compose->menubar);
702 compose->replyinfo = NULL;
703 compose->fwdinfo = NULL;
705 textview = GTK_TEXT_VIEW(compose->text);
706 textbuf = gtk_text_view_get_buffer(textview);
708 undo_block(compose->undostruct);
710 if (item && item->prefs && item->prefs->enable_default_dictionary &&
712 gtkaspell_change_dict(compose->gtkaspell,
713 item->prefs->default_dictionary);
716 if (account->auto_sig)
717 compose_insert_sig(compose, FALSE);
718 gtk_text_buffer_get_start_iter(textbuf, &iter);
719 gtk_text_buffer_place_cursor(textbuf, &iter);
721 if (account->protocol != A_NNTP) {
722 if (mailto && *mailto != '\0') {
723 compose_entries_set(compose, mailto);
725 } else if (item && item->prefs->enable_default_to) {
726 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
727 compose_entry_mark_default_to(compose, item->prefs->default_to);
729 if (item && item->ret_rcpt) {
730 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
734 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
737 * CLAWS: just don't allow return receipt request, even if the user
738 * may want to send an email. simple but foolproof.
740 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
742 compose_add_field_list( compose, listAddress );
748 for (i = 0; i < attach_files->len; i++) {
749 file = g_ptr_array_index(attach_files, i);
750 compose_attach_append(compose, file, file, NULL);
754 compose_show_first_last_header(compose, TRUE);
756 /* Set save folder */
757 if (item && item->prefs && item->prefs->save_copy_to_folder) {
758 gchar *folderidentifier;
760 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
761 folderidentifier = folder_item_get_identifier(item);
762 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
763 g_free(folderidentifier);
766 gtk_widget_grab_focus(compose->header_last->entry);
768 undo_unblock(compose->undostruct);
770 if (prefs_common.auto_exteditor)
771 compose_exec_ext_editor(compose);
777 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
778 const gchar *followupto, gchar * to)
782 if (!account) account = cur_account;
783 g_return_val_if_fail(account != NULL, NULL);
784 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
786 compose = compose_create(account, COMPOSE_NEW);
788 if (prefs_common.auto_sig)
789 compose_insert_sig(compose);
790 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
791 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
793 compose_entry_append(compose, to, COMPOSE_TO);
794 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
795 gtk_widget_grab_focus(compose->subject_entry);
801 void compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
806 g_return_if_fail(msginfo_list != NULL);
808 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
809 g_return_if_fail(msginfo != NULL);
811 list_len = g_slist_length(msginfo_list);
815 compose_reply(msginfo, prefs_common.reply_with_quote,
816 FALSE, prefs_common.default_reply_list, FALSE, body);
818 case COMPOSE_REPLY_WITH_QUOTE:
819 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, body);
821 case COMPOSE_REPLY_WITHOUT_QUOTE:
822 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
824 case COMPOSE_REPLY_TO_SENDER:
825 compose_reply(msginfo, prefs_common.reply_with_quote,
826 FALSE, FALSE, TRUE, body);
828 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
829 compose_followup_and_reply_to(msginfo,
830 prefs_common.reply_with_quote,
833 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
834 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, body);
836 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
837 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
839 case COMPOSE_REPLY_TO_ALL:
840 compose_reply(msginfo, prefs_common.reply_with_quote,
841 TRUE, FALSE, FALSE, body);
843 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
844 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, body);
846 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
847 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
849 case COMPOSE_REPLY_TO_LIST:
850 compose_reply(msginfo, prefs_common.reply_with_quote,
851 FALSE, TRUE, FALSE, body);
853 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
854 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, body);
856 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
857 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
859 case COMPOSE_FORWARD:
860 if (prefs_common.forward_as_attachment) {
861 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
864 compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
868 case COMPOSE_FORWARD_INLINE:
869 /* check if we reply to more than one Message */
871 compose_forward(NULL, msginfo, FALSE, body, FALSE);
874 /* more messages FALL THROUGH */
875 case COMPOSE_FORWARD_AS_ATTACH:
876 compose_forward_multiple(NULL, msginfo_list);
878 case COMPOSE_REDIRECT:
879 compose_redirect(NULL, msginfo);
882 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
886 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
887 gboolean to_ml, gboolean to_sender,
890 compose_generic_reply(msginfo, quote, to_all, to_ml,
891 to_sender, FALSE, body);
894 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
899 compose_generic_reply(msginfo, quote, to_all, FALSE,
900 to_sender, TRUE, body);
903 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
904 gboolean to_all, gboolean to_ml,
906 gboolean followup_and_reply_to,
909 GtkItemFactory *ifactory;
911 PrefsAccount *account = NULL;
912 PrefsAccount *reply_account;
913 GtkTextView *textview;
914 GtkTextBuffer *textbuf;
918 g_return_if_fail(msginfo != NULL);
919 g_return_if_fail(msginfo->folder != NULL);
921 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
923 g_return_if_fail(account != NULL);
925 if (to_sender && account->protocol == A_NNTP &&
926 !followup_and_reply_to) {
928 account_find_from_address(account->address);
930 reply_account = compose_current_mail_account();
934 reply_account = account;
936 compose = compose_create(account, COMPOSE_REPLY);
937 ifactory = gtk_item_factory_from_widget(compose->menubar);
939 menu_set_active(ifactory, "/Options/Remove references", FALSE);
940 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
942 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
943 if (!compose->replyinfo)
944 compose->replyinfo = procmsg_msginfo_copy(msginfo);
946 if (msginfo->folder && msginfo->folder->ret_rcpt)
947 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
949 /* Set save folder */
950 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
951 gchar *folderidentifier;
953 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
954 folderidentifier = folder_item_get_identifier(msginfo->folder);
955 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
956 g_free(folderidentifier);
959 if (compose_parse_header(compose, msginfo) < 0) return;
960 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
961 to_sender, followup_and_reply_to);
962 compose_show_first_last_header(compose, TRUE);
964 textview = (GTK_TEXT_VIEW(compose->text));
965 textbuf = gtk_text_view_get_buffer(textview);
967 undo_block(compose->undostruct);
969 if (msginfo->folder && msginfo->folder->prefs &&
970 msginfo->folder->prefs &&
971 msginfo->folder->prefs->enable_default_dictionary &&
973 gtkaspell_change_dict(compose->gtkaspell,
974 msginfo->folder->prefs->default_dictionary);
980 if (prefs_common.quotemark && *prefs_common.quotemark)
981 qmark = prefs_common.quotemark;
985 compose_quote_fmt(compose, compose->replyinfo,
986 prefs_common.quotefmt,
990 if (account->auto_sig)
991 compose_insert_sig(compose, FALSE);
993 cursor_pos = quote_fmt_get_cursor_pos();
994 gtk_text_buffer_get_start_iter(textbuf, &iter);
995 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cursor_pos);
996 gtk_text_buffer_place_cursor(textbuf, &iter);
998 if (quote && prefs_common.linewrap_quote)
999 compose_wrap_line_all(compose);
1001 gtk_widget_grab_focus(compose->text);
1003 undo_unblock(compose->undostruct);
1005 if (prefs_common.auto_exteditor)
1006 compose_exec_ext_editor(compose);
1009 #define INSERT_FW_HEADER(var, hdr) \
1010 if (msginfo->var && *msginfo->var) { \
1011 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1012 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1013 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1016 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1017 gboolean as_attach, const gchar *body,
1018 gboolean no_extedit)
1021 GtkTextView *textview;
1022 GtkTextBuffer *textbuf;
1025 g_return_val_if_fail(msginfo != NULL, NULL);
1026 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1029 !(account = compose_guess_forward_account_from_msginfo
1031 account = cur_account;
1033 compose = compose_create(account, COMPOSE_FORWARD);
1035 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1036 if (!compose->fwdinfo)
1037 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1039 if (msginfo->subject && *msginfo->subject) {
1040 gchar *buf, *buf2, *p;
1042 buf = p = g_strdup(msginfo->subject);
1043 p += subject_get_prefix_length(p);
1044 memmove(buf, p, strlen(p) + 1);
1046 buf2 = g_strdup_printf("Fw: %s", buf);
1047 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1053 textview = GTK_TEXT_VIEW(compose->text);
1054 textbuf = gtk_text_view_get_buffer(textview);
1059 msgfile = procmsg_get_message_file_path(msginfo);
1060 if (!is_file_exist(msgfile))
1061 g_warning("%s: file not exist\n", msgfile);
1063 compose_attach_append(compose, msgfile, msgfile,
1069 MsgInfo *full_msginfo;
1071 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1073 full_msginfo = procmsg_msginfo_copy(msginfo);
1075 if (prefs_common.fw_quotemark &&
1076 *prefs_common.fw_quotemark)
1077 qmark = prefs_common.fw_quotemark;
1081 compose_quote_fmt(compose, full_msginfo,
1082 prefs_common.fw_quotefmt,
1084 compose_attach_parts(compose, msginfo);
1086 procmsg_msginfo_free(full_msginfo);
1089 if (account->auto_sig)
1090 compose_insert_sig(compose, FALSE);
1092 if (prefs_common.linewrap_quote)
1093 compose_wrap_line_all(compose);
1095 gtk_text_buffer_get_start_iter(textbuf, &iter);
1096 gtk_text_buffer_place_cursor(textbuf, &iter);
1098 #if 0 /* NEW COMPOSE GUI */
1099 if (account->protocol != A_NNTP)
1100 gtk_widget_grab_focus(compose->to_entry);
1102 gtk_widget_grab_focus(compose->newsgroups_entry);
1104 gtk_widget_grab_focus(compose->header_last->entry);
1106 if (!no_extedit && prefs_common.auto_exteditor)
1107 compose_exec_ext_editor(compose);
1110 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1111 gchar *folderidentifier;
1113 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1114 folderidentifier = folder_item_get_identifier(msginfo->folder);
1115 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1116 g_free(folderidentifier);
1122 #undef INSERT_FW_HEADER
1124 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1127 GtkTextView *textview;
1128 GtkTextBuffer *textbuf;
1133 g_return_val_if_fail(msginfo_list != NULL, NULL);
1135 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1136 if (((MsgInfo *)msginfo->data)->folder == NULL)
1139 /* guess account from first selected message */
1141 !(account = compose_guess_forward_account_from_msginfo
1142 (msginfo_list->data)))
1143 account = cur_account;
1145 g_return_val_if_fail(account != NULL, NULL);
1147 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1148 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1149 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1152 compose = compose_create(account, COMPOSE_FORWARD);
1154 textview = GTK_TEXT_VIEW(compose->text);
1155 textbuf = gtk_text_view_get_buffer(textview);
1157 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1158 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1159 if (!is_file_exist(msgfile))
1160 g_warning("%s: file not exist\n", msgfile);
1162 compose_attach_append(compose, msgfile, msgfile,
1167 if (account->auto_sig)
1168 compose_insert_sig(compose, FALSE);
1170 if (prefs_common.linewrap_quote)
1171 compose_wrap_line_all(compose);
1173 gtk_text_buffer_get_start_iter(textbuf, &iter);
1174 gtk_text_buffer_place_cursor(textbuf, &iter);
1176 gtk_widget_grab_focus(compose->header_last->entry);
1178 #if 0 /* NEW COMPOSE GUI */
1179 if (account->protocol != A_NNTP)
1180 gtk_widget_grab_focus(compose->to_entry);
1182 gtk_widget_grab_focus(compose->newsgroups_entry);
1188 void compose_reedit(MsgInfo *msginfo)
1191 PrefsAccount *account = NULL;
1192 GtkTextView *textview;
1193 GtkTextBuffer *textbuf;
1197 gchar buf[BUFFSIZE];
1198 gboolean use_signing = FALSE;
1199 gboolean use_encryption = FALSE;
1200 gchar *privacy_system = NULL;
1202 g_return_if_fail(msginfo != NULL);
1203 g_return_if_fail(msginfo->folder != NULL);
1205 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1206 gchar queueheader_buf[BUFFSIZE];
1209 /* Select Account from queue headers */
1210 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1211 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1212 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1213 account = account_find_from_id(id);
1215 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1216 sizeof(queueheader_buf), "NAID:")) {
1217 id = atoi(&queueheader_buf[strlen("NAID:")]);
1218 account = account_find_from_id(id);
1220 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1221 sizeof(queueheader_buf), "MAID:")) {
1222 id = atoi(&queueheader_buf[strlen("MAID:")]);
1223 account = account_find_from_id(id);
1225 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1226 sizeof(queueheader_buf), "S:")) {
1227 account = account_find_from_address(queueheader_buf);
1229 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1230 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1231 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1232 use_signing = param;
1235 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1236 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1237 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1238 use_encryption = param;
1240 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1241 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1242 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1244 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1245 sizeof(queueheader_buf), "X-Priority: ")) {
1246 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1247 compose->priority = param;
1250 account = msginfo->folder->folder->account;
1252 if (!account && prefs_common.reedit_account_autosel) {
1253 gchar from[BUFFSIZE];
1254 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1255 extract_address(from);
1256 account = account_find_from_address(from);
1259 if (!account) account = cur_account;
1260 g_return_if_fail(account != NULL);
1262 compose = compose_create(account, COMPOSE_REEDIT);
1263 compose->privacy_system = privacy_system;
1264 compose_use_signing(compose, use_signing);
1265 compose_use_encryption(compose, use_encryption);
1266 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1268 if (msginfo->folder->stype == F_QUEUE
1269 || msginfo->folder->stype == F_DRAFT) {
1270 gchar queueheader_buf[BUFFSIZE];
1272 /* Set message save folder */
1273 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1276 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1277 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1278 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1282 if (compose_parse_header(compose, msginfo) < 0) return;
1283 compose_reedit_set_entry(compose, msginfo);
1285 textview = GTK_TEXT_VIEW(compose->text);
1286 textbuf = gtk_text_view_get_buffer(textview);
1287 mark = gtk_text_buffer_get_insert(textbuf);
1288 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1290 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1291 G_CALLBACK(compose_changed_cb),
1294 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1295 G_CALLBACK(text_inserted),
1298 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1299 g_warning("Can't get text part\n");
1301 while (fgets(buf, sizeof(buf), fp) != NULL) {
1303 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1304 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1309 compose_attach_parts(compose, msginfo);
1311 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1312 G_CALLBACK(text_inserted),
1314 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1315 G_CALLBACK(compose_changed_cb),
1318 gtk_widget_grab_focus(compose->text);
1320 if (prefs_common.auto_exteditor)
1321 compose_exec_ext_editor(compose);
1324 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1328 GtkItemFactory *ifactory;
1331 g_return_val_if_fail(msginfo != NULL, NULL);
1334 account = account_get_reply_account(msginfo,
1335 prefs_common.reply_account_autosel);
1336 g_return_val_if_fail(account != NULL, NULL);
1338 compose = compose_create(account, COMPOSE_REDIRECT);
1339 ifactory = gtk_item_factory_from_widget(compose->menubar);
1341 compose->replyinfo = NULL;
1342 compose->fwdinfo = NULL;
1344 compose_show_first_last_header(compose, TRUE);
1346 gtk_widget_grab_focus(compose->header_last->entry);
1348 filename = procmsg_get_message_file(msginfo);
1349 if (filename == NULL)
1352 compose->redirect_filename = filename;
1354 /* Set save folder */
1355 item = msginfo->folder;
1356 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1357 gchar *folderidentifier;
1359 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1360 folderidentifier = folder_item_get_identifier(item);
1361 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1362 g_free(folderidentifier);
1365 compose_attach_parts(compose, msginfo);
1367 if (msginfo->subject)
1368 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1370 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1372 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1373 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), TRUE);
1375 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1376 menu_set_sensitive(ifactory, "/Add...", FALSE);
1377 menu_set_sensitive(ifactory, "/Remove", FALSE);
1378 menu_set_sensitive(ifactory, "/Property...", FALSE);
1380 ifactory = gtk_item_factory_from_widget(compose->menubar);
1381 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1382 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1383 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1384 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1385 menu_set_sensitive(ifactory, "/Edit", FALSE);
1386 menu_set_sensitive(ifactory, "/Options/Sign", FALSE);
1387 menu_set_sensitive(ifactory, "/Options/Encrypt", FALSE);
1388 menu_set_sensitive(ifactory, "/Options/Priority", FALSE);
1389 menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
1390 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1391 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1393 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1394 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1395 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1396 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1397 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1398 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1399 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1404 GList *compose_get_compose_list(void)
1406 return compose_list;
1409 void compose_entry_append(Compose *compose, const gchar *address,
1410 ComposeEntryType type)
1414 if (!address || *address == '\0') return;
1416 #if 0 /* NEW COMPOSE GUI */
1419 entry = GTK_ENTRY(compose->cc_entry);
1422 entry = GTK_ENTRY(compose->bcc_entry);
1424 case COMPOSE_NEWSGROUPS:
1425 entry = GTK_ENTRY(compose->newsgroups_entry);
1429 entry = GTK_ENTRY(compose->to_entry);
1433 text = gtk_entry_get_text(entry);
1435 gtk_entry_append_text(entry, ", ");
1436 gtk_entry_append_text(entry, address);
1444 header = N_("Bcc:");
1446 case COMPOSE_REPLYTO:
1447 header = N_("Reply-To:");
1449 case COMPOSE_NEWSGROUPS:
1450 header = N_("Newsgroups:");
1452 case COMPOSE_FOLLOWUPTO:
1453 header = N_( "Followup-To:");
1460 header = prefs_common.trans_hdr ? gettext(header) : header;
1462 compose_add_header_entry(compose, header, (gchar *)address);
1465 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1467 static GtkStyle *bold_style = NULL;
1468 static GdkColor bold_color;
1472 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1473 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1474 if (gtk_entry_get_text(entry) &&
1475 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1476 gtk_widget_ensure_style(GTK_WIDGET(entry));
1478 PangoFontDescription *font_desc = NULL;
1479 gtkut_convert_int_to_gdk_color
1480 (prefs_common.color_new, &bold_color);
1481 bold_style = gtk_style_copy(gtk_widget_get_style
1482 (GTK_WIDGET(entry)));
1484 font_desc = pango_font_description_from_string
1487 if (bold_style->font_desc)
1488 pango_font_description_free
1489 (bold_style->font_desc);
1490 bold_style->font_desc = font_desc;
1492 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1494 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1499 void compose_toolbar_cb(gint action, gpointer data)
1501 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1502 Compose *compose = (Compose*)toolbar_item->parent;
1504 g_return_if_fail(compose != NULL);
1508 compose_send_cb(compose, 0, NULL);
1511 compose_send_later_cb(compose, 0, NULL);
1514 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1517 compose_insert_file_cb(compose, 0, NULL);
1520 compose_attach_cb(compose, 0, NULL);
1523 compose_insert_sig(compose, FALSE);
1526 compose_ext_editor_cb(compose, 0, NULL);
1528 case A_LINEWRAP_CURRENT:
1529 compose_wrap_line(compose);
1531 case A_LINEWRAP_ALL:
1532 compose_wrap_line_all(compose);
1535 compose_address_cb(compose, 0, NULL);
1538 case A_CHECK_SPELLING:
1539 compose_check_all(compose);
1547 static void compose_entries_set(Compose *compose, const gchar *mailto)
1552 gchar *subject = NULL;
1555 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1558 compose_entry_append(compose, to, COMPOSE_TO);
1560 compose_entry_append(compose, cc, COMPOSE_CC);
1562 compose_entry_append(compose, bcc, COMPOSE_BCC);
1564 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1566 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1567 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1571 mark = gtk_text_buffer_get_insert(buffer);
1572 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1574 gtk_text_buffer_insert(buffer, &iter, body, -1);
1575 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1585 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1587 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1588 {"Cc:", NULL, TRUE},
1589 {"References:", NULL, FALSE},
1590 {"Bcc:", NULL, TRUE},
1591 {"Newsgroups:", NULL, TRUE},
1592 {"Followup-To:", NULL, TRUE},
1593 {"List-Post:", NULL, FALSE},
1594 {"X-Priority:", NULL, FALSE},
1595 {NULL, NULL, FALSE}};
1611 g_return_val_if_fail(msginfo != NULL, -1);
1613 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1614 procheader_get_header_fields(fp, hentry);
1617 if (hentry[H_REPLY_TO].body != NULL) {
1618 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1619 compose->replyto = hentry[H_REPLY_TO].body;
1620 hentry[H_REPLY_TO].body = NULL;
1622 if (hentry[H_CC].body != NULL) {
1623 conv_unmime_header_overwrite(hentry[H_CC].body);
1624 compose->cc = hentry[H_CC].body;
1625 hentry[H_CC].body = NULL;
1627 if (hentry[H_REFERENCES].body != NULL) {
1628 if (compose->mode == COMPOSE_REEDIT)
1629 compose->references = hentry[H_REFERENCES].body;
1631 compose->references = compose_parse_references
1632 (hentry[H_REFERENCES].body, msginfo->msgid);
1633 g_free(hentry[H_REFERENCES].body);
1635 hentry[H_REFERENCES].body = NULL;
1637 if (hentry[H_BCC].body != NULL) {
1638 if (compose->mode == COMPOSE_REEDIT) {
1639 conv_unmime_header_overwrite(hentry[H_BCC].body);
1640 compose->bcc = hentry[H_BCC].body;
1642 g_free(hentry[H_BCC].body);
1643 hentry[H_BCC].body = NULL;
1645 if (hentry[H_NEWSGROUPS].body != NULL) {
1646 conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
1647 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1648 hentry[H_NEWSGROUPS].body = NULL;
1650 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1651 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1652 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1653 hentry[H_FOLLOWUP_TO].body = NULL;
1655 if (hentry[H_LIST_POST].body != NULL) {
1658 extract_address(hentry[H_LIST_POST].body);
1659 if (hentry[H_LIST_POST].body[0] != '\0') {
1660 scan_mailto_url(hentry[H_LIST_POST].body,
1661 &to, NULL, NULL, NULL, NULL);
1663 g_free(compose->ml_post);
1664 compose->ml_post = to;
1667 g_free(hentry[H_LIST_POST].body);
1668 hentry[H_LIST_POST].body = NULL;
1671 /* CLAWS - X-Priority */
1672 if (compose->mode == COMPOSE_REEDIT)
1673 if (hentry[H_X_PRIORITY].body != NULL) {
1676 priority = atoi(hentry[H_X_PRIORITY].body);
1677 g_free(hentry[H_X_PRIORITY].body);
1679 hentry[H_X_PRIORITY].body = NULL;
1681 if (priority < PRIORITY_HIGHEST ||
1682 priority > PRIORITY_LOWEST)
1683 priority = PRIORITY_NORMAL;
1685 compose->priority = priority;
1688 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1689 compose->inreplyto = g_strdup(msginfo->inreplyto);
1690 else if (compose->mode != COMPOSE_REEDIT &&
1691 msginfo->msgid && *msginfo->msgid) {
1692 compose->inreplyto = g_strdup(msginfo->msgid);
1694 if (!compose->references) {
1695 if (msginfo->inreplyto && *msginfo->inreplyto)
1696 compose->references =
1697 g_strdup_printf("<%s>\n\t<%s>",
1701 compose->references =
1702 g_strconcat("<", msginfo->msgid, ">",
1710 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1712 GSList *ref_id_list, *cur;
1716 ref_id_list = references_list_append(NULL, ref);
1717 if (!ref_id_list) return NULL;
1718 if (msgid && *msgid)
1719 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1724 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1725 /* "<" + Message-ID + ">" + CR+LF+TAB */
1726 len += strlen((gchar *)cur->data) + 5;
1728 if (len > MAX_REFERENCES_LEN) {
1729 /* remove second message-ID */
1730 if (ref_id_list && ref_id_list->next &&
1731 ref_id_list->next->next) {
1732 g_free(ref_id_list->next->data);
1733 ref_id_list = g_slist_remove
1734 (ref_id_list, ref_id_list->next->data);
1736 slist_free_strings(ref_id_list);
1737 g_slist_free(ref_id_list);
1744 new_ref = g_string_new("");
1745 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1746 if (new_ref->len > 0)
1747 g_string_append(new_ref, "\n\t");
1748 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
1751 slist_free_strings(ref_id_list);
1752 g_slist_free(ref_id_list);
1754 new_ref_str = new_ref->str;
1755 g_string_free(new_ref, FALSE);
1760 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1761 const gchar *fmt, const gchar *qmark,
1764 static MsgInfo dummyinfo;
1765 gchar *quote_str = NULL;
1769 const gchar *trimmed_body = body;
1772 msginfo = &dummyinfo;
1774 if (qmark != NULL) {
1775 quote_fmt_init(msginfo, NULL, NULL);
1776 quote_fmt_scan_string(qmark);
1779 buf = quote_fmt_get_buffer();
1781 alertpanel_error(_("Quote mark format error."));
1783 Xstrdup_a(quote_str, buf, return NULL)
1786 if (fmt && *fmt != '\0') {
1787 while (trimmed_body && strlen(trimmed_body) > 1
1788 && trimmed_body[0]=='\n')
1791 quote_fmt_init(msginfo, quote_str, trimmed_body);
1792 quote_fmt_scan_string(fmt);
1795 buf = quote_fmt_get_buffer();
1797 alertpanel_error(_("Message reply/forward format error."));
1803 for (p = buf; *p != '\0'; ) {
1804 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1805 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1809 g_signal_handlers_block_by_func(G_OBJECT(buffer),
1810 G_CALLBACK(compose_changed_cb),
1812 g_signal_handlers_block_by_func(G_OBJECT(buffer),
1813 G_CALLBACK(text_inserted),
1816 mark = gtk_text_buffer_get_insert(buffer);
1817 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1819 lastp = strchr(p, '\n');
1820 len = lastp ? lastp - p + 1 : -1;
1822 gtk_text_buffer_insert(buffer, &iter, p, len);
1824 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
1825 G_CALLBACK(compose_changed_cb),
1827 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
1828 G_CALLBACK(text_inserted),
1840 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1841 gboolean to_all, gboolean to_ml,
1843 gboolean followup_and_reply_to)
1845 GSList *cc_list = NULL;
1848 gchar *replyto = NULL;
1849 GHashTable *to_table;
1851 g_return_if_fail(compose->account != NULL);
1852 g_return_if_fail(msginfo != NULL);
1854 if (compose->account->protocol != A_NNTP) {
1855 if (!compose->replyto && to_ml && compose->ml_post
1856 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1857 compose_entry_append(compose,
1860 else if (!(to_all || to_sender)
1862 && msginfo->folder->prefs->enable_default_reply_to) {
1863 compose_entry_append(compose,
1864 msginfo->folder->prefs->default_reply_to,
1867 compose_entry_append(compose,
1868 (compose->replyto && !to_sender)
1869 ? compose->replyto :
1870 msginfo->from ? msginfo->from : "",
1873 if (to_sender || (compose->followup_to &&
1874 !strncmp(compose->followup_to, "poster", 6)))
1875 compose_entry_append
1877 (compose->replyto ? compose->replyto :
1878 msginfo->from ? msginfo->from : ""),
1881 else if (followup_and_reply_to || to_all) {
1882 compose_entry_append
1884 (compose->replyto ? compose->replyto :
1885 msginfo->from ? msginfo->from : ""),
1888 compose_entry_append
1890 compose->followup_to ? compose->followup_to :
1891 compose->newsgroups ? compose->newsgroups : "",
1892 COMPOSE_NEWSGROUPS);
1895 compose_entry_append
1897 compose->followup_to ? compose->followup_to :
1898 compose->newsgroups ? compose->newsgroups : "",
1899 COMPOSE_NEWSGROUPS);
1902 if (msginfo->subject && *msginfo->subject) {
1906 buf = p = g_strdup(msginfo->subject);
1907 p += subject_get_prefix_length(p);
1908 memmove(buf, p, strlen(p) + 1);
1910 buf2 = g_strdup_printf("Re: %s", buf);
1911 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1916 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1918 if (to_ml && compose->ml_post) return;
1919 if (!to_all || compose->account->protocol == A_NNTP) return;
1921 if (compose->replyto) {
1922 Xstrdup_a(replyto, compose->replyto, return);
1923 extract_address(replyto);
1925 if (msginfo->from) {
1926 Xstrdup_a(from, msginfo->from, return);
1927 extract_address(from);
1930 if (replyto && from)
1931 cc_list = address_list_append_with_comments(cc_list, from);
1932 if (to_all && msginfo->folder &&
1933 msginfo->folder->prefs->enable_default_reply_to)
1934 cc_list = address_list_append_with_comments(cc_list,
1935 msginfo->folder->prefs->default_reply_to);
1936 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
1937 cc_list = address_list_append_with_comments(cc_list, compose->cc);
1939 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1941 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
1942 if (compose->account)
1943 g_hash_table_insert(to_table, g_strdup(compose->account->address),
1944 GINT_TO_POINTER(1));
1946 /* remove address on To: and that of current account */
1947 for (cur = cc_list; cur != NULL; ) {
1948 GSList *next = cur->next;
1951 addr = g_strdup(cur->data);
1952 extract_address(addr);
1954 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
1955 cc_list = g_slist_remove(cc_list, cur->data);
1957 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
1961 hash_free_strings(to_table);
1962 g_hash_table_destroy(to_table);
1965 for (cur = cc_list; cur != NULL; cur = cur->next)
1966 compose_entry_append(compose, (gchar *)cur->data,
1968 slist_free_strings(cc_list);
1969 g_slist_free(cc_list);
1974 #define SET_ENTRY(entry, str) \
1977 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1980 #define SET_ADDRESS(type, str) \
1983 compose_entry_append(compose, str, type); \
1986 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1988 g_return_if_fail(msginfo != NULL);
1990 SET_ENTRY(subject_entry, msginfo->subject);
1991 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1992 SET_ADDRESS(COMPOSE_CC, compose->cc);
1993 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1994 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1995 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
1996 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
1998 compose_update_priority_menu_item(compose);
1999 compose_update_privacy_system_menu_item(compose);
2000 compose_show_first_last_header(compose, TRUE);
2006 static void compose_insert_sig(Compose *compose, gboolean replace)
2008 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2009 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2015 g_return_if_fail(compose->account != NULL);
2017 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2018 G_CALLBACK(compose_changed_cb),
2021 mark = gtk_text_buffer_get_insert(buffer);
2022 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2023 cur_pos = gtk_text_iter_get_offset (&iter);
2025 gtk_text_buffer_get_end_iter(buffer, &iter);
2027 if (replace && compose->sig_str) {
2029 GtkTextIter first_iter, start_iter, end_iter;
2031 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2033 if (compose->sig_str[0] == '\0')
2036 found = gtk_text_iter_forward_search(&first_iter,
2038 GTK_TEXT_SEARCH_TEXT_ONLY,
2039 &start_iter, &end_iter,
2043 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2048 g_free(compose->sig_str);
2049 compose->sig_str = compose_get_signature_str(compose);
2050 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2051 compose->sig_str = g_strdup("");
2053 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2055 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2056 cur_pos = gtk_text_buffer_get_char_count (buffer);
2058 gtk_text_buffer_get_iter_at_offset (buffer, &iter, cur_pos);
2059 gtk_text_buffer_place_cursor (buffer, &iter);
2061 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2062 G_CALLBACK(compose_changed_cb),
2067 static gchar *compose_get_signature_str(Compose *compose)
2069 gchar *sig_body = NULL;
2070 gchar *sig_str = NULL;
2072 g_return_val_if_fail(compose->account != NULL, NULL);
2074 if (!compose->account->sig_path)
2077 if (compose->account->sig_type == SIG_FILE) {
2078 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2079 g_warning("can't open signature file: %s\n",
2080 compose->account->sig_path);
2085 if (compose->account->sig_type == SIG_COMMAND)
2086 sig_body = get_command_output(compose->account->sig_path);
2090 tmp = file_read_to_str(compose->account->sig_path);
2093 sig_body = normalize_newlines(tmp);
2097 if (compose->account->sig_sep)
2098 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2101 sig_str = g_strconcat("\n\n", sig_body, NULL);
2108 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2111 GtkTextBuffer *buffer;
2114 gchar buf[BUFFSIZE];
2117 gboolean badtxt = FALSE;
2119 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2121 if ((fp = fopen(file, "rb")) == NULL) {
2122 FILE_OP_ERROR(file, "fopen");
2123 return COMPOSE_INSERT_READ_ERROR;
2126 text = GTK_TEXT_VIEW(compose->text);
2127 buffer = gtk_text_view_get_buffer(text);
2128 mark = gtk_text_buffer_get_insert(buffer);
2129 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2131 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2132 G_CALLBACK(text_inserted),
2135 while (fgets(buf, sizeof(buf), fp) != NULL) {
2136 const gchar *cur_encoding = conv_get_current_charset_str();
2138 if (!g_utf8_validate(buf, -1, NULL))
2139 str = conv_codeset_strdup(buf, cur_encoding, CS_UTF_8);
2141 str = g_strdup(buf);
2145 /* strip <CR> if DOS/Windows file,
2146 replace <CR> with <LF> if Macintosh file. */
2149 if (len > 0 && str[len - 1] != '\n') {
2151 if (str[len] == '\r') str[len] = '\n';
2153 gtk_text_buffer_insert(buffer, &iter, str, -1);
2158 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2159 G_CALLBACK(text_inserted),
2165 return COMPOSE_INSERT_INVALID_CHARACTER;
2167 return COMPOSE_INSERT_SUCCESS;
2170 static void compose_attach_append(Compose *compose, const gchar *file,
2171 const gchar *filename,
2172 const gchar *content_type)
2175 gchar *text[N_ATTACH_COLS];
2181 if (!is_file_exist(file)) {
2182 g_warning("File %s doesn't exist\n", file);
2185 if ((size = get_file_size(file)) < 0) {
2186 g_warning("Can't get file size of %s\n", file);
2190 alertpanel_notice(_("File %s is empty."), file);
2193 if ((fp = fopen(file, "rb")) == NULL) {
2194 alertpanel_error(_("Can't read %s."), file);
2199 #if 0 /* NEW COMPOSE GUI */
2200 if (!compose->use_attach) {
2201 GtkItemFactory *ifactory;
2203 ifactory = gtk_item_factory_from_widget(compose->menubar);
2204 menu_set_active(ifactory, "/View/Attachment", TRUE);
2207 ainfo = g_new0(AttachInfo, 1);
2208 ainfo->file = g_strdup(file);
2211 ainfo->content_type = g_strdup(content_type);
2212 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2214 MsgFlags flags = {0, 0};
2216 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2217 ainfo->encoding = ENC_7BIT;
2219 ainfo->encoding = ENC_8BIT;
2221 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2222 if (msginfo && msginfo->subject)
2223 name = msginfo->subject;
2225 name = g_path_get_basename(filename ? filename : file);
2227 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2229 procmsg_msginfo_free(msginfo);
2231 if (!g_ascii_strncasecmp(content_type, "text", 4))
2232 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2234 ainfo->encoding = ENC_BASE64;
2235 name = g_path_get_basename(filename ? filename : file);
2236 ainfo->name = g_strdup(name);
2240 ainfo->content_type = procmime_get_mime_type(file);
2241 if (!ainfo->content_type) {
2242 ainfo->content_type =
2243 g_strdup("application/octet-stream");
2244 ainfo->encoding = ENC_BASE64;
2245 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2247 procmime_get_encoding_for_text_file(file);
2249 ainfo->encoding = ENC_BASE64;
2250 name = g_path_get_basename(filename ? filename : file);
2251 ainfo->name = g_strdup(name);
2255 if (!strcmp(ainfo->content_type, "unknown")) {
2256 g_free(ainfo->content_type);
2257 ainfo->content_type = g_strdup("application/octet-stream");
2262 text[COL_MIMETYPE] = ainfo->content_type;
2263 text[COL_SIZE] = to_human_readable(size);
2264 text[COL_NAME] = ainfo->name;
2266 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2267 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2270 static void compose_use_signing(Compose *compose, gboolean use_signing)
2272 GtkItemFactory *ifactory;
2273 GtkWidget *menuitem = NULL;
2275 compose->use_signing = use_signing;
2276 ifactory = gtk_item_factory_from_widget(compose->menubar);
2277 menuitem = gtk_item_factory_get_item
2278 (ifactory, "/Options/Sign");
2279 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2283 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2285 GtkItemFactory *ifactory;
2286 GtkWidget *menuitem = NULL;
2288 compose->use_encryption = use_encryption;
2289 ifactory = gtk_item_factory_from_widget(compose->menubar);
2290 menuitem = gtk_item_factory_get_item
2291 (ifactory, "/Options/Encrypt");
2293 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2297 #define NEXT_PART_NOT_CHILD(info) \
2299 node = info->node; \
2300 while (node->children) \
2301 node = g_node_last_child(node); \
2302 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2305 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2309 MimeInfo *firsttext = NULL;
2310 MimeInfo *encrypted = NULL;
2313 const gchar *partname = NULL;
2315 mimeinfo = procmime_scan_message(msginfo);
2316 if (!mimeinfo) return;
2318 if (mimeinfo->node->children == NULL) {
2319 procmime_mimeinfo_free_all(mimeinfo);
2323 /* find first content part */
2324 child = (MimeInfo *) mimeinfo->node->children->data;
2325 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2326 child = (MimeInfo *)child->node->children->data;
2328 if (child->type == MIMETYPE_TEXT) {
2330 debug_print("First text part found\n");
2331 } else if (compose->mode == COMPOSE_REEDIT &&
2332 child->type == MIMETYPE_APPLICATION &&
2333 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2335 val = alertpanel(_("Encrypted message"),
2336 _("Cannot re-edit an encrypted message. \n"
2337 "Discard encrypted part?"),
2338 _("Yes"), _("No"), NULL);
2339 if (val == G_ALERTDEFAULT)
2340 encrypted = (MimeInfo *)child->node->parent->data;
2343 child = (MimeInfo *) mimeinfo->node->children->data;
2344 while (child != NULL) {
2345 if (child == encrypted) {
2346 /* skip this part of tree */
2347 NEXT_PART_NOT_CHILD(child);
2351 if (child->type == MIMETYPE_MULTIPART) {
2352 /* get the actual content */
2353 child = procmime_mimeinfo_next(child);
2357 if (child == firsttext) {
2358 child = procmime_mimeinfo_next(child);
2362 outfile = procmime_get_tmp_file_name(child);
2363 if (procmime_get_part(outfile, child) < 0)
2364 g_warning("Can't get the part of multipart message.");
2366 gchar *content_type;
2368 content_type = procmime_get_content_type_str(child->type, child->subtype);
2369 partname = procmime_mimeinfo_get_parameter(child, "name");
2370 if (partname == NULL)
2372 compose_attach_append(compose, outfile,
2373 partname, content_type);
2374 g_free(content_type);
2377 NEXT_PART_NOT_CHILD(child);
2379 procmime_mimeinfo_free_all(mimeinfo);
2383 #define CHAR_BUF_SIZE 8
2384 #undef NEXT_PART_NOT_CHILD
2386 #define GET_CHAR(iter_p, buf, len) \
2388 GtkTextIter end_iter; \
2390 end_iter = *iter_p; \
2391 gtk_text_iter_forward_char(&end_iter); \
2392 tmp = gtk_text_buffer_get_text(textbuf, iter_p, &end_iter, FALSE); \
2394 glong items_read, items_witten; \
2395 GError *error = NULL; \
2396 gunichar *wide_char; \
2397 strncpy2(buf, tmp, CHAR_BUF_SIZE); \
2398 wide_char = g_utf8_to_ucs4(tmp, -1, \
2399 &items_read, &items_witten, \
2401 if (error != NULL) { \
2402 g_warning("%s\n", error->message); \
2403 g_error_free(error); \
2405 len = wide_char && g_unichar_iswide(*wide_char) ? 2 : 1; \
2406 g_free(wide_char); \
2414 #define DISP_WIDTH(len) \
2415 ((len > 2 && conv_get_current_charset() == C_UTF_8) ? 2 : \
2416 (len == 2 && conv_get_current_charset() == C_UTF_8) ? 1 : len)
2418 #define SPACE_CHARS " \t"
2420 static void compose_wrap_line(Compose *compose)
2422 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2423 GtkTextBuffer *textbuf = gtk_text_view_get_buffer(text);
2425 GtkTextIter insert_iter, iter;
2426 gint ch_len, last_ch_len;
2427 gchar cbuf[CHAR_BUF_SIZE], last_ch;
2429 gint p_start, p_end;
2430 gint line_pos, cur_pos;
2431 gint line_len, cur_len;
2432 gboolean line_end, quoted;
2434 text_len = gtk_text_buffer_get_char_count(textbuf);
2435 mark = gtk_text_buffer_get_insert(textbuf);
2436 gtk_text_buffer_get_iter_at_mark(textbuf, &insert_iter, mark);
2437 cur_pos = gtk_text_iter_get_offset(&insert_iter);
2438 GET_CHAR(&insert_iter, cbuf, ch_len);
2439 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2440 GtkTextIter prev_iter;
2442 return; /* on the paragraph mark */
2443 prev_iter = insert_iter;
2444 gtk_text_iter_backward_char(&prev_iter);
2445 GET_CHAR(&prev_iter, cbuf, ch_len);
2446 if (ch_len == 1 && *cbuf == '\n')
2447 return; /* on the paragraph mark */
2450 /* find paragraph start. */
2451 line_end = quoted = FALSE;
2452 for (iter = insert_iter; gtk_text_iter_backward_char(&iter);) {
2453 GET_CHAR(&iter, cbuf, ch_len);
2454 if (ch_len == 1 && *cbuf == '\n') {
2456 return; /* quoted part */
2458 gtk_text_iter_forward_chars(&iter, 2);
2464 && strchr(prefs_common.quote_chars, *cbuf))
2466 else if (ch_len != 1 || !isspace(*(guchar *)cbuf))
2472 p_start = gtk_text_iter_get_offset(&iter);
2474 /* find paragraph end. */
2476 for (iter = insert_iter; gtk_text_iter_forward_char(&iter);) {
2477 GET_CHAR(&iter, cbuf, ch_len);
2478 if (ch_len == 1 && *cbuf == '\n') {
2481 gtk_text_iter_backward_char(&iter);
2486 if (line_end && ch_len == 1 &&
2487 strchr(prefs_common.quote_chars, *cbuf))
2488 return; /* quoted part */
2493 p_end = gtk_text_iter_get_offset(&iter);
2495 if (p_end >= text_len)
2498 if (p_start >= p_end)
2501 line_len = cur_len = 0;
2505 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2506 gboolean space = FALSE;
2508 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cur_pos);
2510 GET_CHAR(&iter, cbuf, ch_len);
2517 if (ch_len == 1 && isspace(*(guchar *)cbuf))
2520 if (ch_len == 1 && *cbuf == '\n') {
2521 gboolean replace = FALSE;
2522 GtkTextIter next_iter = iter;
2524 gtk_text_iter_forward_char(&next_iter);
2526 if (last_ch_len == 1 && !isspace((guchar)last_ch)) {
2527 if (cur_pos + 1 < p_end) {
2528 GET_CHAR(&next_iter, cbuf, ch_len);
2530 !isspace(*(guchar *)cbuf))
2534 gtk_text_buffer_delete(textbuf, &iter, &next_iter);
2536 gtk_text_buffer_insert(textbuf, &iter, " ", 1);
2542 gtk_text_buffer_get_iter_at_offset
2543 (textbuf, &iter, cur_pos);
2548 last_ch_len = ch_len;
2552 line_pos = cur_pos + 1;
2553 line_len = cur_len + ch_len;
2556 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, line_pos);
2558 if (cur_len + ch_len > prefs_common.linewrap_len &&
2561 GtkTextIter prev_iter = iter;
2563 gtk_text_iter_backward_char(&prev_iter);
2565 GET_CHAR(&prev_iter, cbuf, ch_len);
2566 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2567 gtk_text_buffer_delete(textbuf, &prev_iter, &iter);
2577 gtk_text_buffer_insert(textbuf, &iter, "\n", 1);
2581 cur_len = cur_len - line_len + ch_len;
2587 line_pos = cur_pos + 1;
2588 line_len = cur_len + ch_len;
2596 /* Darko: used when I debug wrapping */
2597 void dump_text(GtkTextBuffer *textbuf, int pos, int tlen, int breakoncr)
2600 gchar cbuf[CHAR_BUF_SIZE];
2601 GtkTextIter iter, end_iter;
2603 printf("%d [", pos);
2604 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, pos);
2605 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter, pos + tlen);
2606 for (; gtk_text_iter_forward_char(&iter) &&
2607 gtk_text_iter_compare(&iter, &end_iter) < 0;) {
2608 GET_CHAR(&iter, cbuf, clen);
2609 if (clen < 0) break;
2610 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2612 fwrite(cbuf, clen, 1, stdout);
2620 WAIT_FOR_INDENT_CHAR,
2621 WAIT_FOR_INDENT_CHAR_OR_SPACE
2624 /* return indent length, we allow:
2625 > followed by spaces/tabs
2626 | followed by spaces/tabs
2627 uppercase characters immediately followed by >,
2628 and the repeating sequences of the above */
2629 /* return indent length */
2630 static guint get_indent_length(GtkTextBuffer *textbuf, guint start_pos, guint text_len)
2633 guint i, ch_len, alnum_cnt = 0;
2634 IndentState state = WAIT_FOR_INDENT_CHAR;
2635 gchar cbuf[CHAR_BUF_SIZE];
2639 if (prefs_common.quote_chars == NULL) {
2643 for (i = start_pos; i < text_len; i++) {
2646 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, i);
2647 GET_CHAR(&iter, cbuf, ch_len);
2651 if (cbuf[0] == '\n')
2654 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2655 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2658 case WAIT_FOR_SPACE:
2659 if (is_space == FALSE)
2661 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2663 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2664 if (is_indent == FALSE && is_space == FALSE &&
2665 !isupper((guchar)cbuf[0]))
2667 if (is_space == TRUE) {
2669 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2670 } else if (is_indent == TRUE) {
2672 state = WAIT_FOR_SPACE;
2675 state = WAIT_FOR_INDENT_CHAR;
2678 case WAIT_FOR_INDENT_CHAR:
2679 if (is_indent == FALSE && !isupper((guchar)cbuf[0]))
2681 if (is_indent == TRUE) {
2683 && !strchr(prefs_common.quote_chars, cbuf[0]))
2686 state = WAIT_FOR_SPACE;
2697 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2703 /* insert quotation string when line was wrapped */
2704 static guint ins_quote(GtkTextBuffer *textbuf, GtkTextIter *iter,
2706 guint prev_line_pos, guint text_len,
2712 GtkTextIter iter1, iter2;
2715 gtk_text_buffer_get_iter_at_offset(textbuf, &iter1,
2717 gtk_text_buffer_get_iter_at_offset(textbuf, &iter2,
2718 prev_line_pos + indent_len);
2719 text = gtk_text_buffer_get_text(textbuf, &iter1, &iter2, FALSE);
2720 if (!text) return 0;
2722 gtk_text_buffer_insert(textbuf, iter, text, -1);
2723 ins_len = g_utf8_strlen(text, -1);
2731 static gboolean is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, guint start_pos)
2735 GtkTextIter end_iter;
2736 if (!compose->account->sig_sep)
2739 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, start_pos+1);
2740 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
2741 start_pos+strlen(compose->account->sig_sep)+1);
2743 if (!strcmp(gtk_text_iter_get_text(&iter, &end_iter),
2744 compose->account->sig_sep)) {
2746 gtk_text_buffer_get_iter_at_offset(textbuf, &iter,
2747 start_pos+strlen(compose->account->sig_sep)+1);
2748 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
2749 start_pos+strlen(compose->account->sig_sep)+2);
2751 if (!strcmp(gtk_text_iter_get_text(&iter, &end_iter),"\n"));
2760 /* check if we should join the next line */
2761 static gboolean join_next_line_is_needed(GtkTextBuffer *textbuf,
2762 guint start_pos, guint tlen,
2763 guint prev_ilen, gboolean autowrap)
2765 guint indent_len, ch_len;
2766 gboolean do_join = FALSE;
2767 gchar cbuf[CHAR_BUF_SIZE];
2769 indent_len = get_indent_length(textbuf, start_pos, tlen);
2771 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2773 gtk_text_buffer_get_iter_at_offset(textbuf, &iter,
2774 start_pos + indent_len);
2775 GET_CHAR(&iter, cbuf, ch_len);
2777 if (ch_len > 0 && (cbuf[0] != '\n'))
2784 static void compose_wrap_line_all(Compose *compose)
2786 compose_wrap_line_all_full(compose, FALSE);
2789 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2791 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2792 GtkTextBuffer *textbuf = gtk_text_view_get_buffer(text);
2793 GtkTextIter iter, end_iter;
2795 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2796 gint line_len = 0, cur_len = 0;
2798 gboolean is_new_line = TRUE, do_delete = FALSE;
2800 gboolean linewrap_quote = TRUE;
2801 gboolean set_editable_pos = FALSE;
2802 gint editable_pos = 0;
2803 guint linewrap_len = prefs_common.linewrap_len;
2804 gchar *qfmt = prefs_common.quotemark;
2805 gchar cbuf[CHAR_BUF_SIZE];
2806 GtkTextMark *cursor_mark = gtk_text_buffer_get_insert(textbuf);
2808 tlen = gtk_text_buffer_get_char_count(textbuf);
2810 for (; cur_pos < tlen; cur_pos++) {
2811 /* mark position of new line - needed for quotation wrap */
2814 i_len = get_indent_length(textbuf, cur_pos, tlen);
2816 is_new_line = FALSE;
2820 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cur_pos);
2821 GET_CHAR(&iter, cbuf, ch_len);
2823 /* fix line length for tabs */
2824 if (ch_len == 1 && *cbuf == '\t') {
2825 guint tab_width = 8;
2826 guint tab_offset = line_len % tab_width;
2828 line_len += tab_width - tab_offset - 1;
2832 /* we have encountered line break */
2833 if (ch_len == 1 && *cbuf == '\n') {
2835 gchar cb[CHAR_BUF_SIZE];
2837 /* should we join the next line */
2838 if ((autowrap || i_len != cur_len) && do_delete &&
2839 !is_sig_separator(compose, textbuf, cur_pos+i_len) &&
2840 join_next_line_is_needed
2841 (textbuf, cur_pos + 1, tlen, i_len, autowrap)) {
2846 /* skip delete if it is continuous URL */
2847 if (do_delete && (line_pos - p_pos <= i_len) &&
2848 gtkut_text_buffer_is_uri_string(textbuf, line_pos,
2852 /* should we delete to perform smart wrapping */
2853 if (line_len < linewrap_len && do_delete) {
2854 /* get rid of newline */
2855 gtk_text_buffer_get_iter_at_offset(textbuf,
2859 gtk_text_iter_forward_char(&end_iter);
2860 gtk_text_buffer_delete(textbuf, &iter, &end_iter);
2863 /* if text starts with quote fmt or with
2864 indent string, delete them */
2867 ilen = gtkut_text_buffer_str_compare_n
2868 (textbuf, cur_pos, p_pos, i_len,
2872 gtk_text_iter_forward_chars
2874 gtk_text_buffer_delete(textbuf,
2881 gtk_text_buffer_get_iter_at_offset(textbuf,
2884 GET_CHAR(&iter, cb, clen);
2886 /* insert space if it's alphanumeric */
2887 if ((cur_pos != line_pos) &&
2888 ((clen > 1) || isalnum((guchar)cb[0]))) {
2889 GtkTextIter cursor_iter;
2890 gboolean go_back = FALSE;
2891 gtk_text_buffer_get_iter_at_mark(textbuf, &cursor_iter, cursor_mark);
2892 if (gtk_text_iter_get_offset(&iter) ==
2893 gtk_text_iter_get_offset(&cursor_iter))
2896 gtk_text_buffer_insert(textbuf, &iter,
2899 gtk_text_buffer_get_iter_at_mark(textbuf, &cursor_iter, cursor_mark);
2900 gtk_text_iter_backward_chars(&cursor_iter, 1);
2901 gtk_text_buffer_place_cursor(textbuf, &cursor_iter);
2906 /* and start over with current line */
2907 cur_pos = p_pos - 1;
2909 line_len = cur_len = 0;
2913 g_print("after delete l_pos=");
2914 dump_text(textbuf, line_pos, tlen, 1);
2916 /* move beginning of line if we are on LF */
2917 gtk_text_buffer_get_iter_at_offset(textbuf,
2920 GET_CHAR(&iter, cb, clen);
2921 if (clen == 1 && *cb == '\n')
2924 g_print("new line_pos=%d\n", line_pos);
2930 /* mark new line beginning */
2931 line_pos = cur_pos + 1;
2932 line_len = cur_len = 0;
2943 /* possible line break */
2944 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2945 line_pos = cur_pos + 1;
2946 line_len = cur_len + ch_len;
2949 /* are we over wrapping length set in preferences ? */
2950 if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
2954 g_print("should wrap cur_pos=%d ", cur_pos);
2955 dump_text(textbuf, p_pos, tlen, 1);
2956 dump_text(textbuf, line_pos, tlen, 1);
2958 /* force wrapping if it is one long word but not URL */
2959 if (line_pos - p_pos <= i_len)
2960 if (!gtkut_text_buffer_is_uri_string
2961 (textbuf, line_pos, tlen))
2962 line_pos = cur_pos - 1;
2964 g_print("new line_pos=%d\n", line_pos);
2967 gtk_text_buffer_get_iter_at_offset(textbuf,
2970 GET_CHAR(&iter, cbuf, clen);
2972 /* if next character is space delete it */
2973 if (clen == 1 && isspace(*(guchar *)cbuf)) {
2974 if (p_pos + i_len != line_pos ||
2975 !gtkut_text_buffer_is_uri_string
2976 (textbuf, line_pos, tlen)) {
2977 /* workaround for correct cursor
2979 if (set_editable_pos == FALSE) {
2980 GtkTextMark *ins = gtk_text_buffer_get_insert(textbuf);
2981 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, ins);
2982 editable_pos = gtk_text_iter_get_offset(&iter);
2983 if (editable_pos == line_pos)
2984 set_editable_pos = TRUE;
2986 gtk_text_buffer_get_iter_at_offset(textbuf,
2989 gtk_text_buffer_get_iter_at_offset(textbuf,
2992 gtk_text_buffer_delete(textbuf, &iter, &end_iter);
2993 //gtk_stext_set_point(text, line_pos);
2994 //gtk_stext_backward_delete(text, 1);
3003 /* if it is URL at beginning of line don't wrap */
3004 if (p_pos + i_len == line_pos &&
3005 gtkut_text_buffer_is_uri_string(textbuf, line_pos, tlen)) {
3007 g_print("found URL at ");
3008 dump_text(textbuf, line_pos, tlen, 1);
3014 gtk_text_buffer_get_iter_at_offset(textbuf,
3017 gtk_text_buffer_insert(textbuf, &iter, "\n", 1);
3018 //gtk_stext_set_point(text, line_pos);
3019 //gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
3020 //gtk_stext_compact_buffer(text);
3023 /* for loop will increase it */
3024 cur_pos = line_pos - 1;
3025 /* start over with current line */
3027 line_len = cur_len = 0;
3028 if (autowrap || i_len > 0) {
3033 g_print("after CR insert ");
3034 dump_text(textbuf, line_pos, tlen, 1);
3035 dump_text(textbuf, cur_pos, tlen, 1);
3038 /* should we insert quotation ? */
3039 if (linewrap_quote && i_len) {
3040 /* only if line is not already quoted */
3041 if (!gtkut_text_buffer_str_compare
3042 (textbuf, line_pos, tlen, qfmt)) {
3045 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, line_pos);
3047 if (line_pos - p_pos > i_len) {
3049 (textbuf, &iter, i_len, p_pos,
3054 g_print("after quote insert ");
3055 dump_text(textbuf, line_pos, tlen, 1);
3063 line_pos = cur_pos + 1;
3064 line_len = cur_len + ch_len;
3066 /* advance to next character in buffer */
3070 if (set_editable_pos && editable_pos <= tlen) {
3071 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, editable_pos);
3072 gtk_text_buffer_place_cursor(textbuf, &iter);
3077 #undef CHAR_BUF_SIZE
3079 static void compose_set_title(Compose *compose)
3084 edited = compose->modified ? _(" [Edited]") : "";
3085 if (compose->account && compose->account->address)
3086 str = g_strdup_printf(_("%s - Compose message%s"),
3087 compose->account->address, edited);
3089 str = g_strdup_printf(_("Compose message%s"), edited);
3090 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3095 * compose_current_mail_account:
3097 * Find a current mail account (the currently selected account, or the
3098 * default account, if a news account is currently selected). If a
3099 * mail account cannot be found, display an error message.
3101 * Return value: Mail account, or NULL if not found.
3103 static PrefsAccount *
3104 compose_current_mail_account(void)
3108 if (cur_account && cur_account->protocol != A_NNTP)
3111 ac = account_get_default();
3112 if (!ac || ac->protocol == A_NNTP) {
3113 alertpanel_error(_("Account for sending mail is not specified.\n"
3114 "Please select a mail account before sending."));
3121 static void compose_select_account(Compose *compose, PrefsAccount *account,
3124 GtkItemFactory *ifactory;
3126 g_return_if_fail(account != NULL);
3128 compose->account = account;
3130 compose_set_title(compose);
3132 ifactory = gtk_item_factory_from_widget(compose->menubar);
3134 if (account->protocol == A_NNTP) {
3135 gtk_widget_show(compose->newsgroups_hbox);
3136 gtk_widget_show(compose->newsgroups_entry);
3137 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
3138 compose->use_newsgroups = TRUE;
3140 menu_set_active(ifactory, "/View/To", FALSE);
3141 menu_set_sensitive(ifactory, "/View/To", TRUE);
3142 menu_set_active(ifactory, "/View/Cc", FALSE);
3143 menu_set_sensitive(ifactory, "/View/Cc", TRUE);
3144 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
3146 gtk_widget_hide(compose->newsgroups_hbox);
3147 gtk_widget_hide(compose->newsgroups_entry);
3148 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
3149 gtk_widget_queue_resize(compose->table_vbox);
3150 compose->use_newsgroups = FALSE;
3152 menu_set_active(ifactory, "/View/To", TRUE);
3153 menu_set_sensitive(ifactory, "/View/To", FALSE);
3154 menu_set_active(ifactory, "/View/Cc", TRUE);
3155 menu_set_sensitive(ifactory, "/View/Cc", FALSE);
3156 menu_set_active(ifactory, "/View/Followup to", FALSE);
3157 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
3160 if (account->set_autocc) {
3161 compose_entry_show(compose, COMPOSE_ENTRY_CC);
3162 if (account->auto_cc && compose->mode != COMPOSE_REEDIT)
3163 compose_entry_set(compose, account->auto_cc,
3166 if (account->set_autobcc) {
3167 compose_entry_show(compose, COMPOSE_ENTRY_BCC);
3168 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
3169 compose_entry_set(compose, account->auto_bcc,
3172 if (account->set_autoreplyto) {
3173 compose_entry_show(compose, COMPOSE_ENTRY_REPLY_TO);
3174 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
3175 compose_entry_set(compose, account->auto_replyto,
3176 COMPOSE_ENTRY_REPLY_TO);
3181 if (account->default_sign)
3182 menu_set_active(ifactory, "/Options/Sign", TRUE);
3184 menu_set_active(ifactory, "/Options/Sign", FALSE);
3185 if (account->default_encrypt)
3186 menu_set_active(ifactory, "/Options/Encrypt", TRUE);
3188 menu_set_active(ifactory, "/Options/Encrypt", FALSE);
3190 activate_privacy_system(compose, account);
3192 if (!init && compose->mode != COMPOSE_REDIRECT)
3193 compose_insert_sig(compose, TRUE);
3196 gboolean compose_check_for_valid_recipient(Compose *compose) {
3197 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3198 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3199 gboolean recipient_found = FALSE;
3203 /* free to and newsgroup list */
3204 slist_free_strings(compose->to_list);
3205 g_slist_free(compose->to_list);
3206 compose->to_list = NULL;
3208 slist_free_strings(compose->newsgroup_list);
3209 g_slist_free(compose->newsgroup_list);
3210 compose->newsgroup_list = NULL;
3212 /* search header entries for to and newsgroup entries */
3213 for (list = compose->header_list; list; list = list->next) {
3216 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3217 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3219 if (entry[0] != '\0') {
3220 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3221 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3222 compose->to_list = address_list_append(compose->to_list, entry);
3223 recipient_found = TRUE;
3226 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3227 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3228 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3229 recipient_found = TRUE;
3236 return recipient_found;
3239 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3243 if (compose_check_for_valid_recipient(compose) == FALSE) {
3244 alertpanel_error(_("Recipient is not specified."));
3248 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3249 if (*str == '\0' && check_subject == TRUE) {
3252 aval = alertpanel(_("Send"),
3253 _("Subject is empty. Send it anyway?"),
3254 _("Yes"), _("No"), NULL);
3255 if (aval != G_ALERTDEFAULT)
3262 gint compose_send(Compose *compose)
3269 compose_allow_user_actions (compose, FALSE);
3270 compose->sending = TRUE;
3272 if (compose_check_entries(compose, TRUE) == FALSE)
3275 val = compose_queue(compose, &msgnum, &folder);
3278 alertpanel_error(_("Could not queue message for sending"));
3283 if (prefs_common.send_dialog_mode != SEND_DIALOG_ALWAYS) {
3284 compose->sending = FALSE;
3285 gtk_widget_destroy(compose->window);
3286 /* No more compose access in the normal codepath
3287 * after this point! */
3291 alertpanel_error(_("The message was queued but could not be "
3292 "sent.\nUse \"Send queued messages\" from "
3293 "the main window to retry."));
3294 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3295 compose->sending = FALSE;
3296 compose_allow_user_actions (compose, TRUE);
3301 msgpath = folder_item_fetch_msg(folder, msgnum);
3302 val = procmsg_send_message_queue(msgpath);
3305 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3306 compose->sending = FALSE;
3307 compose_allow_user_actions (compose, TRUE);
3309 folder_item_remove_msg(folder, msgnum);
3310 folder_item_scan(folder);
3315 folder_item_remove_msg(folder, msgnum);
3316 folder_item_scan(folder);
3317 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS)
3318 gtk_widget_destroy(compose->window);
3320 alertpanel_error(_("The message was queued but could not be "
3321 "sent.\nUse \"Send queued messages\" from "
3322 "the main window to retry."));
3323 if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
3324 compose_allow_user_actions (compose, TRUE);
3325 compose->sending = FALSE;
3333 compose_allow_user_actions (compose, TRUE);
3334 compose->sending = FALSE;
3339 static gboolean compose_use_attach(Compose *compose)
3341 return gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL;
3344 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3347 gchar buf[BUFFSIZE];
3349 gboolean first_to_address;
3350 gboolean first_cc_address;
3352 ComposeHeaderEntry *headerentry;
3353 const gchar *headerentryname;
3357 debug_print("Writing redirect header\n");
3359 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3360 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3362 first_to_address = TRUE;
3363 first_cc_address = TRUE;
3364 for (list = compose->header_list; list; list = list->next) {
3365 headerentry = ((ComposeHeaderEntry *)list->data);
3366 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3368 if (g_utf8_collate(headerentryname, cc_hdr) == 0
3369 || g_utf8_collate(headerentryname, to_hdr) == 0) {
3370 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3371 Xstrdup_a(str, entstr, return -1);
3373 if (str[0] != '\0') {
3374 compose_convert_header
3375 (buf, sizeof(buf), str,
3376 strlen("Resent-To") + 2, TRUE);
3377 if (g_utf8_collate(headerentryname, to_hdr) == 0) {
3378 if (first_to_address) {
3379 fprintf(fp, "Resent-To: ");
3380 first_to_address = FALSE;
3385 if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
3386 if (first_cc_address) {
3388 fprintf(fp, "Resent-Cc: ");
3389 first_cc_address = FALSE;
3395 fprintf(fp, "%s", buf);
3399 /* if (!first_address) { */
3406 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3408 gchar buf[BUFFSIZE];
3410 const gchar *entstr;
3411 /* struct utsname utsbuf; */
3413 g_return_val_if_fail(fp != NULL, -1);
3414 g_return_val_if_fail(compose->account != NULL, -1);
3415 g_return_val_if_fail(compose->account->address != NULL, -1);
3418 get_rfc822_date(buf, sizeof(buf));
3419 fprintf(fp, "Resent-Date: %s\n", buf);
3422 if (compose->account->name && *compose->account->name) {
3423 compose_convert_header
3424 (buf, sizeof(buf), compose->account->name,
3425 strlen("From: "), TRUE);
3426 fprintf(fp, "Resent-From: %s <%s>\n",
3427 buf, compose->account->address);
3429 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3432 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3433 if (*entstr != '\0') {
3434 Xstrdup_a(str, entstr, return -1);
3437 compose_convert_header(buf, sizeof(buf), str,
3438 strlen("Subject: "), FALSE);
3439 fprintf(fp, "Subject: %s\n", buf);
3443 /* Resent-Message-ID */
3444 if (compose->account->gen_msgid) {
3445 generate_msgid(buf, sizeof(buf));
3446 fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
3447 compose->msgid = g_strdup(buf);
3450 compose_redirect_write_headers_from_headerlist(compose, fp);
3452 /* separator between header and body */
3458 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
3462 gchar buf[BUFFSIZE];
3464 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
3465 FILE_OP_ERROR(compose->redirect_filename, "fopen");
3469 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3470 /* should filter returnpath, delivered-to */
3471 if (g_ascii_strncasecmp(buf, "Return-Path:",
3472 strlen("Return-Path:")) == 0 ||
3473 g_ascii_strncasecmp(buf, "Delivered-To:",
3474 strlen("Delivered-To:")) == 0 ||
3475 g_ascii_strncasecmp(buf, "Received:",
3476 strlen("Received:")) == 0 ||
3477 g_ascii_strncasecmp(buf, "Subject:",
3478 strlen("Subject:")) == 0 ||
3479 g_ascii_strncasecmp(buf, "X-UIDL:",
3480 strlen("X-UIDL:")) == 0)
3483 if (fputs(buf, fdest) == -1)
3486 if (!prefs_common.redirect_keep_from) {
3487 if (g_ascii_strncasecmp(buf, "From:",
3488 strlen("From:")) == 0) {
3489 fputs(" (by way of ", fdest);
3490 if (compose->account->name
3491 && *compose->account->name) {
3492 compose_convert_header
3494 compose->account->name,
3497 fprintf(fdest, "%s <%s>",
3499 compose->account->address);
3501 fprintf(fdest, "%s",
3502 compose->account->address);
3507 if (fputs("\n", fdest) == -1)
3511 compose_redirect_write_headers(compose, fdest);
3513 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3514 if (fwrite(buf, sizeof(gchar), len, fdest) != len)
3527 static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
3529 GtkTextBuffer *buffer;
3530 GtkTextIter start, end;
3533 const gchar *out_codeset;
3534 EncodingType encoding;
3535 MimeInfo *mimemsg, *mimetext;
3537 /* create message MimeInfo */
3538 mimemsg = procmime_mimeinfo_new();
3539 mimemsg->type = MIMETYPE_MESSAGE;
3540 mimemsg->subtype = g_strdup("rfc822");
3541 mimemsg->content = MIMECONTENT_MEM;
3542 mimemsg->data.mem = compose_get_header(compose);
3544 /* Create text part MimeInfo */
3545 /* get all composed text */
3546 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
3547 gtk_text_buffer_get_start_iter(buffer, &start);
3548 gtk_text_buffer_get_end_iter(buffer, &end);
3549 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
3550 if (is_ascii_str(chars)) {
3553 out_codeset = CS_US_ASCII;
3554 encoding = ENC_7BIT;
3556 const gchar *src_codeset;
3558 out_codeset = conv_get_outgoing_charset_str();
3559 if (!g_ascii_strcasecmp(out_codeset, CS_US_ASCII))
3560 out_codeset = CS_ISO_8859_1;
3562 if (prefs_common.encoding_method == CTE_BASE64)
3563 encoding = ENC_BASE64;
3564 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
3565 encoding = ENC_QUOTED_PRINTABLE;
3566 else if (prefs_common.encoding_method == CTE_8BIT)
3567 encoding = ENC_8BIT;
3569 encoding = procmime_get_encoding_for_charset(out_codeset);
3571 src_codeset = CS_UTF_8;
3572 /* if current encoding is US-ASCII, set it the same as
3573 outgoing one to prevent code conversion failure */
3574 if (!g_ascii_strcasecmp(src_codeset, CS_US_ASCII))
3575 src_codeset = out_codeset;
3577 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3578 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3580 if (action == COMPOSE_WRITE_FOR_SEND) {
3581 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3586 msg = g_strdup_printf(_("Can't convert the character encoding of the message from\n"
3588 "Send it anyway?"), src_codeset, out_codeset);
3589 aval = alertpanel_with_type
3590 (_("Error"), msg, _("Yes"), _("+No"), NULL, NULL, ALERT_ERROR);
3593 if (aval != G_ALERTDEFAULT) {
3598 out_codeset = src_codeset;
3604 out_codeset = src_codeset;
3610 mimetext = procmime_mimeinfo_new();
3611 mimetext->content = MIMECONTENT_MEM;
3612 mimetext->data.mem = buf;
3613 mimetext->type = MIMETYPE_TEXT;
3614 mimetext->subtype = g_strdup("plain");
3615 g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
3616 g_strdup(out_codeset));
3617 if (encoding != ENC_UNKNOWN)
3618 procmime_encode_content(mimetext, encoding);
3620 /* append attachment parts */
3621 if (compose_use_attach(compose)) {
3622 MimeInfo *mimempart;
3624 mimempart = procmime_mimeinfo_new();
3625 mimempart->content = MIMECONTENT_EMPTY;
3626 mimempart->type = MIMETYPE_MULTIPART;
3627 mimempart->subtype = g_strdup("mixed");
3628 g_hash_table_insert(mimempart->typeparameters, g_strdup("boundary"),
3629 generate_mime_boundary(NULL));
3631 mimetext->disposition = DISPOSITIONTYPE_INLINE;
3633 g_node_append(mimempart->node, mimetext->node);
3634 g_node_append(mimemsg->node, mimempart->node);
3636 compose_add_attachments(compose, mimempart);
3638 g_node_append(mimemsg->node, mimetext->node);
3640 /* sign message if sending */
3641 if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing &&
3642 privacy_system_can_sign(compose->privacy_system))
3643 if (!privacy_sign(compose->privacy_system, mimemsg))
3646 procmime_write_mimeinfo(mimemsg, fp);
3651 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3653 GtkTextBuffer *buffer;
3654 GtkTextIter start, end;