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/gtkthemes.h> */
53 #include <gtk/gtkdnd.h>
58 #include <sys/types.h>
62 /* #include <sys/utsname.h> */
69 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
76 #include "mainwindow.h"
78 #include "addressbook.h"
79 #include "folderview.h"
82 #include "stock_pixmap.h"
83 #include "send_message.h"
86 #include "customheader.h"
87 #include "prefs_common.h"
88 #include "prefs_account.h"
92 #include "procheader.h"
94 #include "statusbar.h"
97 #include "quoted-printable.h"
100 #include "gtkutils.h"
102 #include "alertpanel.h"
103 #include "manage_window.h"
104 #include "gtkshruler.h"
106 #include "addr_compl.h"
107 #include "quote_fmt.h"
108 #include "template.h"
110 #include "foldersel.h"
114 # include "rfc2015.h"
124 #define N_ATTACH_COLS 3
128 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
129 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
130 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
131 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
132 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
133 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
134 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
135 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
136 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
137 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
138 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
139 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
140 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
141 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
142 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
143 } ComposeCallAdvancedAction;
147 PRIORITY_HIGHEST = 1,
156 COMPOSE_INSERT_SUCCESS,
157 COMPOSE_INSERT_READ_ERROR,
158 COMPOSE_INSERT_INVALID_CHARACTER,
159 COMPOSE_INSERT_NO_FILE
160 } ComposeInsertResult;
162 #define B64_LINE_SIZE 57
163 #define B64_BUFFSIZE 77
165 #define MAX_REFERENCES_LEN 999
167 static GdkColor quote_color = {0, 0, 0, 0xbfff};
169 static GList *compose_list = NULL;
171 Compose *compose_generic_new (PrefsAccount *account,
174 GPtrArray *attach_files,
175 GList *listAddress );
177 static Compose *compose_create (PrefsAccount *account,
180 static GtkWidget *compose_account_option_menu_create
182 static void compose_set_template_menu (Compose *compose);
183 static void compose_template_apply (Compose *compose,
186 static void compose_destroy (Compose *compose);
188 static void compose_entries_set (Compose *compose,
189 const gchar *mailto);
190 static gint compose_parse_header (Compose *compose,
192 static gchar *compose_parse_references (const gchar *ref,
195 static gchar *compose_quote_fmt (Compose *compose,
201 static void compose_reply_set_entry (Compose *compose,
207 followup_and_reply_to);
208 static void compose_reedit_set_entry (Compose *compose,
210 static void compose_insert_sig (Compose *compose,
212 static gchar *compose_get_signature_str (Compose *compose);
213 static ComposeInsertResult compose_insert_file (Compose *compose,
215 static void compose_attach_append (Compose *compose,
218 const gchar *content_type);
219 static void compose_attach_parts (Compose *compose,
221 static void compose_wrap_line (Compose *compose);
222 static void compose_wrap_line_all (Compose *compose);
223 static void compose_wrap_line_all_full (Compose *compose,
225 static void compose_set_title (Compose *compose);
226 static void compose_select_account (Compose *compose,
227 PrefsAccount *account,
230 static PrefsAccount *compose_current_mail_account(void);
231 /* static gint compose_send (Compose *compose); */
232 static gboolean compose_check_for_valid_recipient
234 static gboolean compose_check_entries (Compose *compose,
235 gboolean check_subject);
236 static gint compose_write_to_file (Compose *compose,
239 static gint compose_write_body_to_file (Compose *compose,
241 static gint compose_remove_reedit_target (Compose *compose);
242 void compose_remove_draft (Compose *compose);
243 static gint compose_queue (Compose *compose,
246 static gint compose_queue_sub (Compose *compose,
249 gboolean check_subject);
250 static void compose_write_attach (Compose *compose,
252 static gint compose_write_headers (Compose *compose,
254 const gchar *charset,
255 EncodingType encoding,
258 static void compose_convert_header (gchar *dest,
262 gboolean addr_field);
263 static void compose_generate_msgid (gchar *buf,
266 static void compose_attach_info_free (AttachInfo *ainfo);
267 static void compose_attach_remove_selected (Compose *compose);
269 static void compose_attach_property (Compose *compose);
270 static void compose_attach_property_create (gboolean *cancelled);
271 static void attach_property_ok (GtkWidget *widget,
272 gboolean *cancelled);
273 static void attach_property_cancel (GtkWidget *widget,
274 gboolean *cancelled);
275 static gint attach_property_delete_event (GtkWidget *widget,
277 gboolean *cancelled);
278 static gboolean attach_property_key_pressed (GtkWidget *widget,
280 gboolean *cancelled);
282 static void compose_exec_ext_editor (Compose *compose);
283 static gint compose_exec_ext_editor_real (const gchar *file);
284 static gboolean compose_ext_editor_kill (Compose *compose);
285 static void compose_input_cb (gpointer data,
287 GdkInputCondition condition);
288 static void compose_set_ext_editor_sensitive (Compose *compose,
291 static void compose_undo_state_changed (UndoMain *undostruct,
296 static gint calc_cursor_xpos (GtkTextView *text,
300 static void compose_create_header_entry (Compose *compose);
301 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
302 static void compose_update_priority_menu_item(Compose * compose);
304 static void compose_add_field_list ( Compose *compose,
305 GList *listAddress );
307 /* callback functions */
309 static gboolean compose_edit_size_alloc (GtkEditable *widget,
310 GtkAllocation *allocation,
311 GtkSHRuler *shruler);
312 static void account_activated (GtkMenuItem *menuitem,
314 static void attach_selected (GtkCList *clist,
319 static gboolean attach_button_pressed (GtkWidget *widget,
320 GdkEventButton *event,
322 static gboolean attach_key_pressed (GtkWidget *widget,
326 static void compose_send_cb (gpointer data,
329 static void compose_send_later_cb (gpointer data,
333 static void compose_draft_cb (gpointer data,
337 static void compose_attach_cb (gpointer data,
340 static void compose_insert_file_cb (gpointer data,
343 static void compose_insert_sig_cb (gpointer data,
347 static void compose_close_cb (gpointer data,
351 static void compose_address_cb (gpointer data,
354 static void compose_template_activate_cb(GtkWidget *widget,
357 static void compose_ext_editor_cb (gpointer data,
361 static gint compose_delete_cb (GtkWidget *widget,
364 static void compose_destroy_cb (GtkWidget *widget,
367 static void compose_undo_cb (Compose *compose);
368 static void compose_redo_cb (Compose *compose);
369 static void compose_cut_cb (Compose *compose);
370 static void compose_copy_cb (Compose *compose);
371 static void compose_paste_cb (Compose *compose);
372 static void compose_paste_as_quote_cb (Compose *compose);
373 static void compose_allsel_cb (Compose *compose);
375 static void compose_advanced_action_cb (Compose *compose,
376 ComposeCallAdvancedAction action);
378 static void compose_grab_focus_cb (GtkWidget *widget,
381 static void compose_changed_cb (GtkTextBuffer *textbuf,
384 static void compose_toggle_autowrap_cb (gpointer data,
389 static void compose_toggle_to_cb (gpointer data,
392 static void compose_toggle_cc_cb (gpointer data,
395 static void compose_toggle_bcc_cb (gpointer data,
398 static void compose_toggle_replyto_cb (gpointer data,
401 static void compose_toggle_followupto_cb(gpointer data,
404 static void compose_toggle_attach_cb (gpointer data,
408 static void compose_toggle_ruler_cb (gpointer data,
412 static void compose_toggle_sign_cb (gpointer data,
415 static void compose_toggle_encrypt_cb (gpointer data,
418 static void compose_set_gnupg_mode_cb (gpointer data,
421 static void compose_update_gnupg_mode_menu_item(Compose * compose);
422 static void activate_gnupg_mode (Compose *compose,
423 PrefsAccount *account);
425 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
427 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
429 static void compose_set_priority_cb (gpointer data,
433 static void compose_attach_drag_received_cb (GtkWidget *widget,
434 GdkDragContext *drag_context,
437 GtkSelectionData *data,
441 static void compose_insert_drag_received_cb (GtkWidget *widget,
442 GdkDragContext *drag_context,
445 GtkSelectionData *data,
451 static void to_activated (GtkWidget *widget,
453 static void newsgroups_activated (GtkWidget *widget,
455 static void cc_activated (GtkWidget *widget,
457 static void bcc_activated (GtkWidget *widget,
459 static void replyto_activated (GtkWidget *widget,
461 static void followupto_activated (GtkWidget *widget,
463 static void subject_activated (GtkWidget *widget,
467 static void text_activated (GtkWidget *widget,
469 static void text_inserted (GtkTextBuffer *buffer,
474 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
475 gboolean to_all, gboolean to_ml,
477 gboolean followup_and_reply_to,
480 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
481 ComposeHeaderEntry *headerentry);
482 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
484 ComposeHeaderEntry *headerentry);
485 static gboolean compose_headerentry_button_pressed (GtkWidget *entry,
486 GdkEventButton *event,
489 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
492 static void compose_check_all (Compose *compose);
493 static void compose_highlight_all (Compose *compose);
494 static void compose_check_backwards (Compose *compose);
495 static void compose_check_forwards_go (Compose *compose);
498 static gboolean compose_send_control_enter (Compose *compose);
499 static gint compose_defer_auto_save_draft (Compose *compose);
500 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
502 static GtkItemFactoryEntry compose_popup_entries[] =
504 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
505 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
506 {N_("/---"), NULL, NULL, 0, "<Separator>"},
507 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
510 static GtkItemFactoryEntry compose_entries[] =
512 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
513 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
514 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
515 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
516 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
517 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
519 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
520 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
521 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
522 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
523 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
524 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
525 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
526 {N_("/_Edit/Paste as _quotation"),
527 NULL, compose_paste_as_quote_cb, 0, NULL},
528 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
529 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
530 {N_("/_Edit/A_dvanced/Move a character backward"),
532 compose_advanced_action_cb,
533 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
535 {N_("/_Edit/A_dvanced/Move a character forward"),
537 compose_advanced_action_cb,
538 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
540 {N_("/_Edit/A_dvanced/Move a word backward"),
542 compose_advanced_action_cb,
543 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
545 {N_("/_Edit/A_dvanced/Move a word forward"),
547 compose_advanced_action_cb,
548 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
550 {N_("/_Edit/A_dvanced/Move to beginning of line"),
551 NULL, /* "<control>A" */
552 compose_advanced_action_cb,
553 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
555 {N_("/_Edit/A_dvanced/Move to end of line"),
557 compose_advanced_action_cb,
558 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
560 {N_("/_Edit/A_dvanced/Move to previous line"),
562 compose_advanced_action_cb,
563 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
565 {N_("/_Edit/A_dvanced/Move to next line"),
567 compose_advanced_action_cb,
568 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
570 {N_("/_Edit/A_dvanced/Delete a character backward"),
572 compose_advanced_action_cb,
573 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
575 {N_("/_Edit/A_dvanced/Delete a character forward"),
577 compose_advanced_action_cb,
578 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
580 {N_("/_Edit/A_dvanced/Delete a word backward"),
581 NULL, /* "<control>W" */
582 compose_advanced_action_cb,
583 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
585 {N_("/_Edit/A_dvanced/Delete a word forward"),
586 NULL, /* "<alt>D", */
587 compose_advanced_action_cb,
588 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
590 {N_("/_Edit/A_dvanced/Delete line"),
592 compose_advanced_action_cb,
593 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
595 {N_("/_Edit/A_dvanced/Delete entire line"),
597 compose_advanced_action_cb,
598 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
600 {N_("/_Edit/A_dvanced/Delete to end of line"),
602 compose_advanced_action_cb,
603 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
605 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
606 {N_("/_Edit/_Wrap current paragraph"),
607 "<control>L", compose_wrap_line, 0, NULL},
608 {N_("/_Edit/Wrap all long _lines"),
609 "<control><alt>L", compose_wrap_line_all, 0, NULL},
610 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
611 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
612 {N_("/_Edit/Edit with e_xternal editor"),
613 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
615 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
616 {N_("/_Spelling/_Check all or check selection"),
617 NULL, compose_check_all, 0, NULL},
618 {N_("/_Spelling/_Highlight all misspelled words"),
619 NULL, compose_highlight_all, 0, NULL},
620 {N_("/_Spelling/Check _backwards misspelled word"),
621 NULL, compose_check_backwards , 0, NULL},
622 {N_("/_Spelling/_Forward to next misspelled word"),
623 NULL, compose_check_forwards_go, 0, NULL},
624 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
625 {N_("/_Spelling/_Spelling Configuration"),
626 NULL, NULL, 0, "<Branch>"},
628 #if 0 /* NEW COMPOSE GUI */
629 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
630 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
631 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
632 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
633 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
634 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
635 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
636 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
637 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
638 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
639 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
641 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
642 {N_("/_Message/_Send"), "<control>Return",
643 compose_send_cb, 0, NULL},
644 {N_("/_Message/Send _later"), "<shift><control>S",
645 compose_send_later_cb, 0, NULL},
646 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
647 {N_("/_Message/Save to _draft folder"),
648 "<shift><control>D", compose_draft_cb, 0, NULL},
649 {N_("/_Message/Save and _keep editing"),
650 "<control>S", compose_draft_cb, 1, NULL},
651 #if 0 /* NEW COMPOSE GUI */
652 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
653 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
654 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
655 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
656 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
657 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
658 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
659 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
660 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
663 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
664 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
665 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
666 {N_("/_Message/Mode"), NULL, NULL, 0, "<Branch>"},
667 {N_("/_Message/Mode/MIME"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_DETACH, "<RadioItem>"},
668 {N_("/_Message/Mode/Inline"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_INLINE, "/Message/Mode/MIME"},
669 #endif /* USE_GPGME */
670 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
671 {N_("/_Message/_Priority"), NULL, NULL, 0, "<Branch>"},
672 {N_("/_Message/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
673 {N_("/_Message/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
674 {N_("/_Message/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
675 {N_("/_Message/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
676 {N_("/_Message/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
677 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
678 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
679 {N_("/_Message/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
680 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
681 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
682 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
683 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
684 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
685 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
686 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
689 static GtkTargetEntry compose_mime_types[] =
691 {"text/uri-list", 0, 0}
694 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
695 GPtrArray *attach_files)
697 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
700 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
702 return compose_generic_new(account, NULL, item, NULL, NULL);
705 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
707 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
710 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
711 GPtrArray *attach_files, GList *listAddress )
714 GtkTextView *textview;
715 GtkTextBuffer *textbuf;
717 GtkItemFactory *ifactory;
719 if (item && item->prefs && item->prefs->enable_default_account)
720 account = account_find_from_id(item->prefs->default_account);
722 if (!account) account = cur_account;
723 g_return_val_if_fail(account != NULL, NULL);
725 compose = compose_create(account, COMPOSE_NEW);
726 ifactory = gtk_item_factory_from_widget(compose->menubar);
728 compose->replyinfo = NULL;
729 compose->fwdinfo = NULL;
731 textview = GTK_TEXT_VIEW(compose->text);
732 textbuf = gtk_text_view_get_buffer(textview);
735 if (item && item->prefs && item->prefs->enable_default_dictionary &&
737 gtkaspell_change_dict(compose->gtkaspell,
738 item->prefs->default_dictionary);
741 if (account->auto_sig)
742 compose_insert_sig(compose, FALSE);
743 gtk_text_buffer_get_start_iter(textbuf, &iter);
744 gtk_text_buffer_place_cursor(textbuf, &iter);
746 if (account->protocol != A_NNTP) {
747 if (mailto && *mailto != '\0') {
748 compose_entries_set(compose, mailto);
750 } else if (item && item->prefs->enable_default_to) {
751 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
752 compose_entry_mark_default_to(compose, item->prefs->default_to);
754 if (item && item->ret_rcpt) {
755 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
759 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
762 * CLAWS: just don't allow return receipt request, even if the user
763 * may want to send an email. simple but foolproof.
765 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
767 compose_add_field_list( compose, listAddress );
773 for (i = 0; i < attach_files->len; i++) {
774 file = g_ptr_array_index(attach_files, i);
775 compose_attach_append(compose, file, file, NULL);
779 compose_show_first_last_header(compose, TRUE);
781 /* Set save folder */
782 if (item && item->prefs && item->prefs->save_copy_to_folder) {
783 gchar *folderidentifier;
785 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
786 folderidentifier = folder_item_get_identifier(item);
787 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
788 g_free(folderidentifier);
791 gtk_widget_grab_focus(compose->header_last->entry);
793 undo_unblock(compose->undostruct);
795 if (prefs_common.auto_exteditor)
796 compose_exec_ext_editor(compose);
802 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
803 const gchar *followupto, gchar * to)
807 if (!account) account = cur_account;
808 g_return_val_if_fail(account != NULL, NULL);
809 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
811 compose = compose_create(account, COMPOSE_NEW);
813 if (prefs_common.auto_sig)
814 compose_insert_sig(compose);
815 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
816 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
818 compose_entry_append(compose, to, COMPOSE_TO);
819 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
820 gtk_widget_grab_focus(compose->subject_entry);
826 void compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
831 g_return_if_fail(msginfo_list != NULL);
833 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
834 g_return_if_fail(msginfo != NULL);
836 list_len = g_slist_length(msginfo_list);
840 compose_reply(msginfo, prefs_common.reply_with_quote,
841 FALSE, prefs_common.default_reply_list, FALSE, body);
843 case COMPOSE_REPLY_WITH_QUOTE:
844 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, body);
846 case COMPOSE_REPLY_WITHOUT_QUOTE:
847 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
849 case COMPOSE_REPLY_TO_SENDER:
850 compose_reply(msginfo, prefs_common.reply_with_quote,
851 FALSE, FALSE, TRUE, body);
853 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
854 compose_followup_and_reply_to(msginfo,
855 prefs_common.reply_with_quote,
858 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
859 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, body);
861 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
862 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
864 case COMPOSE_REPLY_TO_ALL:
865 compose_reply(msginfo, prefs_common.reply_with_quote,
866 TRUE, FALSE, FALSE, body);
868 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
869 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, body);
871 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
872 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
874 case COMPOSE_REPLY_TO_LIST:
875 compose_reply(msginfo, prefs_common.reply_with_quote,
876 FALSE, TRUE, FALSE, body);
878 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
879 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, body);
881 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
882 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
884 case COMPOSE_FORWARD:
885 if (prefs_common.forward_as_attachment) {
886 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
889 compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
893 case COMPOSE_FORWARD_INLINE:
894 /* check if we reply to more than one Message */
896 compose_forward(NULL, msginfo, FALSE, body, FALSE);
899 /* more messages FALL THROUGH */
900 case COMPOSE_FORWARD_AS_ATTACH:
901 compose_forward_multiple(NULL, msginfo_list);
903 case COMPOSE_REDIRECT:
904 compose_redirect(NULL, msginfo);
907 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
911 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
912 gboolean to_ml, gboolean to_sender,
915 compose_generic_reply(msginfo, quote, to_all, to_ml,
916 to_sender, FALSE, body);
919 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
924 compose_generic_reply(msginfo, quote, to_all, FALSE,
925 to_sender, TRUE, body);
928 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
929 gboolean to_all, gboolean to_ml,
931 gboolean followup_and_reply_to,
934 GtkItemFactory *ifactory;
936 PrefsAccount *account = NULL;
937 PrefsAccount *reply_account;
938 GtkTextView *textview;
939 GtkTextBuffer *textbuf;
943 g_return_if_fail(msginfo != NULL);
944 g_return_if_fail(msginfo->folder != NULL);
946 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
948 g_return_if_fail(account != NULL);
950 if (to_sender && account->protocol == A_NNTP &&
951 !followup_and_reply_to) {
953 account_find_from_address(account->address);
955 reply_account = compose_current_mail_account();
959 reply_account = account;
961 compose = compose_create(account, COMPOSE_REPLY);
962 ifactory = gtk_item_factory_from_widget(compose->menubar);
964 menu_set_active(ifactory, "/Message/Remove references", FALSE);
965 menu_set_sensitive(ifactory, "/Message/Remove references", TRUE);
967 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
968 if (!compose->replyinfo)
969 compose->replyinfo = procmsg_msginfo_copy(msginfo);
971 if (msginfo->folder && msginfo->folder->ret_rcpt)
972 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
974 /* Set save folder */
975 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
976 gchar *folderidentifier;
978 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
979 folderidentifier = folder_item_get_identifier(msginfo->folder);
980 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
981 g_free(folderidentifier);
984 if (compose_parse_header(compose, msginfo) < 0) return;
985 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
986 to_sender, followup_and_reply_to);
987 compose_show_first_last_header(compose, TRUE);
989 textview = (GTK_TEXT_VIEW(compose->text));
990 textbuf = gtk_text_view_get_buffer(textview);
993 if (msginfo->folder && msginfo->folder->prefs &&
994 msginfo->folder->prefs &&
995 msginfo->folder->prefs->enable_default_dictionary &&
997 gtkaspell_change_dict(compose->gtkaspell,
998 msginfo->folder->prefs->default_dictionary);
1004 if (prefs_common.quotemark && *prefs_common.quotemark)
1005 qmark = prefs_common.quotemark;
1009 compose_quote_fmt(compose, compose->replyinfo,
1010 prefs_common.quotefmt,
1014 if (account->auto_sig)
1015 compose_insert_sig(compose, FALSE);
1017 if (quote && prefs_common.linewrap_quote)
1018 compose_wrap_line_all(compose);
1020 cursor_pos = quote_fmt_get_cursor_pos();
1021 gtk_text_buffer_get_start_iter(textbuf, &iter);
1022 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cursor_pos);
1023 gtk_text_buffer_place_cursor(textbuf, &iter);
1025 if (quote && prefs_common.linewrap_quote) {
1026 compose_wrap_line_all(compose);
1027 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), TRUE);
1030 gtk_widget_grab_focus(compose->text);
1032 undo_unblock(compose->undostruct);
1034 if (prefs_common.auto_exteditor)
1035 compose_exec_ext_editor(compose);
1038 #define INSERT_FW_HEADER(var, hdr) \
1039 if (msginfo->var && *msginfo->var) { \
1040 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1041 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1042 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1045 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1046 gboolean as_attach, const gchar *body,
1047 gboolean no_extedit)
1050 GtkTextView *textview;
1051 GtkTextBuffer *textbuf;
1054 g_return_val_if_fail(msginfo != NULL, NULL);
1055 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1058 !(account = compose_guess_forward_account_from_msginfo
1060 account = cur_account;
1062 compose = compose_create(account, COMPOSE_FORWARD);
1064 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1065 if (!compose->fwdinfo)
1066 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1068 if (msginfo->subject && *msginfo->subject) {
1069 gchar *buf, *buf2, *p;
1071 buf = p = g_strdup(msginfo->subject);
1072 p += subject_get_prefix_length(p);
1073 memmove(buf, p, strlen(p) + 1);
1075 buf2 = g_strdup_printf("Fw: %s", buf);
1076 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1082 textview = GTK_TEXT_VIEW(compose->text);
1083 textbuf = gtk_text_view_get_buffer(textview);
1088 msgfile = procmsg_get_message_file_path(msginfo);
1089 if (!is_file_exist(msgfile))
1090 g_warning("%s: file not exist\n", msgfile);
1092 compose_attach_append(compose, msgfile, msgfile,
1098 MsgInfo *full_msginfo;
1100 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1102 full_msginfo = procmsg_msginfo_copy(msginfo);
1104 if (prefs_common.fw_quotemark &&
1105 *prefs_common.fw_quotemark)
1106 qmark = prefs_common.fw_quotemark;
1110 compose_quote_fmt(compose, full_msginfo,
1111 prefs_common.fw_quotefmt,
1113 compose_attach_parts(compose, msginfo);
1115 procmsg_msginfo_free(full_msginfo);
1118 if (account->auto_sig)
1119 compose_insert_sig(compose, FALSE);
1121 if (prefs_common.linewrap_quote)
1122 compose_wrap_line_all(compose);
1124 gtk_text_buffer_get_start_iter(textbuf, &iter);
1125 gtk_text_buffer_place_cursor(textbuf, &iter);
1127 #if 0 /* NEW COMPOSE GUI */
1128 if (account->protocol != A_NNTP)
1129 gtk_widget_grab_focus(compose->to_entry);
1131 gtk_widget_grab_focus(compose->newsgroups_entry);
1133 gtk_widget_grab_focus(compose->header_last->entry);
1135 if (!no_extedit && prefs_common.auto_exteditor)
1136 compose_exec_ext_editor(compose);
1139 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1140 gchar *folderidentifier;
1142 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1143 folderidentifier = folder_item_get_identifier(msginfo->folder);
1144 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1145 g_free(folderidentifier);
1151 #undef INSERT_FW_HEADER
1153 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1156 GtkTextView *textview;
1157 GtkTextBuffer *textbuf;
1162 g_return_val_if_fail(msginfo_list != NULL, NULL);
1164 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1165 if (((MsgInfo *)msginfo->data)->folder == NULL)
1168 /* guess account from first selected message */
1170 !(account = compose_guess_forward_account_from_msginfo
1171 (msginfo_list->data)))
1172 account = cur_account;
1174 g_return_val_if_fail(account != NULL, NULL);
1176 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1177 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1178 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1181 compose = compose_create(account, COMPOSE_FORWARD);
1183 textview = GTK_TEXT_VIEW(compose->text);
1184 textbuf = gtk_text_view_get_buffer(textview);
1186 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1187 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1188 if (!is_file_exist(msgfile))
1189 g_warning("%s: file not exist\n", msgfile);
1191 compose_attach_append(compose, msgfile, msgfile,
1196 if (account->auto_sig)
1197 compose_insert_sig(compose, FALSE);
1199 if (prefs_common.linewrap_quote)
1200 compose_wrap_line_all(compose);
1202 gtk_text_buffer_get_start_iter(textbuf, &iter);
1203 gtk_text_buffer_place_cursor(textbuf, &iter);
1205 gtk_widget_grab_focus(compose->header_last->entry);
1207 #if 0 /* NEW COMPOSE GUI */
1208 if (account->protocol != A_NNTP)
1209 gtk_widget_grab_focus(compose->to_entry);
1211 gtk_widget_grab_focus(compose->newsgroups_entry);
1217 void compose_reedit(MsgInfo *msginfo)
1220 PrefsAccount *account = NULL;
1221 GtkTextView *textview;
1222 GtkTextBuffer *textbuf;
1226 gchar buf[BUFFSIZE];
1228 g_return_if_fail(msginfo != NULL);
1229 g_return_if_fail(msginfo->folder != NULL);
1231 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1232 gchar queueheader_buf[BUFFSIZE];
1235 /* Select Account from queue headers */
1236 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1237 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1238 id = atoi(&queueheader_buf[22]);
1239 account = account_find_from_id(id);
1241 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1242 sizeof(queueheader_buf), "NAID:")) {
1243 id = atoi(&queueheader_buf[5]);
1244 account = account_find_from_id(id);
1246 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1247 sizeof(queueheader_buf), "MAID:")) {
1248 id = atoi(&queueheader_buf[5]);
1249 account = account_find_from_id(id);
1251 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1252 sizeof(queueheader_buf), "S:")) {
1253 account = account_find_from_address(queueheader_buf);
1256 account = msginfo->folder->folder->account;
1258 if (!account && prefs_common.reedit_account_autosel) {
1259 gchar from[BUFFSIZE];
1260 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1261 extract_address(from);
1262 account = account_find_from_address(from);
1265 if (!account) account = cur_account;
1266 g_return_if_fail(account != NULL);
1268 compose = compose_create(account, COMPOSE_REEDIT);
1269 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1271 if (msginfo->folder->stype == F_QUEUE
1272 || msginfo->folder->stype == F_DRAFT) {
1273 gchar queueheader_buf[BUFFSIZE];
1275 /* Set message save folder */
1276 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1279 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1280 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1281 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1285 if (compose_parse_header(compose, msginfo) < 0) return;
1286 compose_reedit_set_entry(compose, msginfo);
1288 textview = GTK_TEXT_VIEW(compose->text);
1289 textbuf = gtk_text_view_get_buffer(textview);
1290 mark = gtk_text_buffer_get_insert(textbuf);
1291 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1293 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1294 G_CALLBACK(compose_changed_cb),
1297 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1298 g_warning("Can't get text part\n");
1300 while (fgets(buf, sizeof(buf), fp) != NULL) {
1302 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1307 compose_attach_parts(compose, msginfo);
1309 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1310 G_CALLBACK(compose_changed_cb),
1313 gtk_widget_grab_focus(compose->text);
1315 if (prefs_common.auto_exteditor)
1316 compose_exec_ext_editor(compose);
1319 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1323 GtkItemFactory *ifactory;
1326 g_return_val_if_fail(msginfo != NULL, NULL);
1329 account = account_get_reply_account(msginfo,
1330 prefs_common.reply_account_autosel);
1331 g_return_val_if_fail(account != NULL, NULL);
1333 compose = compose_create(account, COMPOSE_REDIRECT);
1334 ifactory = gtk_item_factory_from_widget(compose->menubar);
1336 compose->replyinfo = NULL;
1337 compose->fwdinfo = NULL;
1339 compose_show_first_last_header(compose, TRUE);
1341 gtk_widget_grab_focus(compose->header_last->entry);
1343 filename = procmsg_get_message_file(msginfo);
1344 if (filename == NULL)
1347 compose->redirect_filename = filename;
1349 /* Set save folder */
1350 item = msginfo->folder;
1351 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1352 gchar *folderidentifier;
1354 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1355 folderidentifier = folder_item_get_identifier(item);
1356 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1357 g_free(folderidentifier);
1360 compose_attach_parts(compose, msginfo);
1362 if (msginfo->subject)
1363 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1365 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1367 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1368 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), TRUE);
1370 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1371 menu_set_sensitive(ifactory, "/Add...", FALSE);
1372 menu_set_sensitive(ifactory, "/Remove", FALSE);
1373 menu_set_sensitive(ifactory, "/Property...", FALSE);
1375 ifactory = gtk_item_factory_from_widget(compose->menubar);
1376 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
1377 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
1378 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
1379 menu_set_sensitive(ifactory, "/Edit", FALSE);
1380 menu_set_sensitive(ifactory, "/Message/Save to draft folder", FALSE);
1381 menu_set_sensitive(ifactory, "/Message/Save and keep editing", FALSE);
1383 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
1384 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
1385 menu_set_sensitive(ifactory, "/Message/Mode/MIME", FALSE);
1386 menu_set_sensitive(ifactory, "/Message/Mode/Inline", FALSE);
1388 menu_set_sensitive(ifactory, "/Message/Priority", FALSE);
1389 menu_set_sensitive(ifactory, "/Message/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_strcasecmp(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, 0, 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_sprintfa(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),
1813 mark = gtk_text_buffer_get_insert(buffer);
1814 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1816 lastp = strchr(p, '\n');
1817 len = lastp ? lastp - p + 1 : -1;
1818 gtk_text_buffer_insert(buffer, &iter, p, len);
1820 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
1821 G_CALLBACK(compose_changed_cb),
1833 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1834 gboolean to_all, gboolean to_ml,
1836 gboolean followup_and_reply_to)
1838 GSList *cc_list = NULL;
1841 gchar *replyto = NULL;
1842 GHashTable *to_table;
1844 g_return_if_fail(compose->account != NULL);
1845 g_return_if_fail(msginfo != NULL);
1847 if (compose->account->protocol != A_NNTP) {
1848 if (!compose->replyto && to_ml && compose->ml_post
1849 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1850 compose_entry_append(compose,
1853 else if (!(to_all || to_sender)
1855 && msginfo->folder->prefs->enable_default_reply_to) {
1856 compose_entry_append(compose,
1857 msginfo->folder->prefs->default_reply_to,
1860 compose_entry_append(compose,
1861 (compose->replyto && !to_sender)
1862 ? compose->replyto :
1863 msginfo->from ? msginfo->from : "",
1866 if (to_sender || (compose->followup_to &&
1867 !strncmp(compose->followup_to, "poster", 6)))
1868 compose_entry_append
1870 (compose->replyto ? compose->replyto :
1871 msginfo->from ? msginfo->from : ""),
1874 else if (followup_and_reply_to || to_all) {
1875 compose_entry_append
1877 (compose->replyto ? compose->replyto :
1878 msginfo->from ? msginfo->from : ""),
1881 compose_entry_append
1883 compose->followup_to ? compose->followup_to :
1884 compose->newsgroups ? compose->newsgroups : "",
1885 COMPOSE_NEWSGROUPS);
1888 compose_entry_append
1890 compose->followup_to ? compose->followup_to :
1891 compose->newsgroups ? compose->newsgroups : "",
1892 COMPOSE_NEWSGROUPS);
1895 if (msginfo->subject && *msginfo->subject) {
1899 buf = p = g_strdup(msginfo->subject);
1900 p += subject_get_prefix_length(p);
1901 memmove(buf, p, strlen(p) + 1);
1903 buf2 = g_strdup_printf("Re: %s", buf);
1904 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1909 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1911 if (to_ml && compose->ml_post) return;
1912 if (!to_all || compose->account->protocol == A_NNTP) return;
1914 if (compose->replyto) {
1915 Xstrdup_a(replyto, compose->replyto, return);
1916 extract_address(replyto);
1918 if (msginfo->from) {
1919 Xstrdup_a(from, msginfo->from, return);
1920 extract_address(from);
1923 if (replyto && from)
1924 cc_list = address_list_append_with_comments(cc_list, from);
1925 if (to_all && msginfo->folder &&
1926 msginfo->folder->prefs->enable_default_reply_to)
1927 cc_list = address_list_append_with_comments(cc_list,
1928 msginfo->folder->prefs->default_reply_to);
1929 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
1930 cc_list = address_list_append_with_comments(cc_list, compose->cc);
1932 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1934 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
1935 if (compose->account)
1936 g_hash_table_insert(to_table, g_strdup(compose->account->address),
1937 GINT_TO_POINTER(1));
1939 /* remove address on To: and that of current account */
1940 for (cur = cc_list; cur != NULL; ) {
1941 GSList *next = cur->next;
1944 addr = g_strdup(cur->data);
1945 extract_address(addr);
1947 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
1948 cc_list = g_slist_remove(cc_list, cur->data);
1950 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
1954 hash_free_strings(to_table);
1955 g_hash_table_destroy(to_table);
1958 for (cur = cc_list; cur != NULL; cur = cur->next)
1959 compose_entry_append(compose, (gchar *)cur->data,
1961 slist_free_strings(cc_list);
1962 g_slist_free(cc_list);
1967 #define SET_ENTRY(entry, str) \
1970 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1973 #define SET_ADDRESS(type, str) \
1976 compose_entry_append(compose, str, type); \
1979 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1981 g_return_if_fail(msginfo != NULL);
1983 SET_ENTRY(subject_entry, msginfo->subject);
1984 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1985 SET_ADDRESS(COMPOSE_CC, compose->cc);
1986 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1987 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1988 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
1989 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
1991 compose_update_priority_menu_item(compose);
1993 compose_update_gnupg_mode_menu_item(compose);
1995 compose_show_first_last_header(compose, TRUE);
2002 static void compose_insert_sig(Compose *compose, gboolean replace)
2004 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2005 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2011 g_return_if_fail(compose->account != NULL);
2013 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2014 G_CALLBACK(compose_changed_cb),
2017 mark = gtk_text_buffer_get_insert(buffer);
2018 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2019 cur_pos = gtk_text_iter_get_offset (&iter);
2021 gtk_text_buffer_get_end_iter(buffer, &iter);
2023 if (replace && compose->sig_str) {
2025 GtkTextIter first_iter, start_iter, end_iter;
2027 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2029 if (compose->sig_str[0] == '\0')
2032 found = gtk_text_iter_forward_search(&first_iter,
2034 GTK_TEXT_SEARCH_TEXT_ONLY,
2035 &start_iter, &end_iter,
2039 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2044 g_free(compose->sig_str);
2045 compose->sig_str = compose_get_signature_str(compose);
2046 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2047 compose->sig_str = g_strdup("");
2049 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2051 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2052 cur_pos = gtk_text_buffer_get_char_count (buffer);
2054 gtk_text_buffer_get_iter_at_offset (buffer, &iter, cur_pos);
2055 gtk_text_buffer_place_cursor (buffer, &iter);
2057 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2058 G_CALLBACK(compose_changed_cb),
2063 static gchar *compose_get_signature_str(Compose *compose)
2065 gchar *sig_body = NULL;
2066 gchar *sig_str = NULL;
2068 g_return_val_if_fail(compose->account != NULL, NULL);
2070 if (!compose->account->sig_path)
2073 if (compose->account->sig_type == SIG_FILE) {
2074 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2075 g_warning("can't open signature file: %s\n",
2076 compose->account->sig_path);
2081 if (compose->account->sig_type == SIG_COMMAND)
2082 sig_body = get_command_output(compose->account->sig_path);
2086 tmp = file_read_to_str(compose->account->sig_path);
2089 sig_body = normalize_newlines(tmp);
2093 if (compose->account->sig_sep)
2094 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2097 sig_str = g_strconcat("\n\n", sig_body, NULL);
2104 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2107 GtkTextBuffer *buffer;
2110 gchar buf[BUFFSIZE];
2113 gboolean badtxt = FALSE;
2115 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2117 if ((fp = fopen(file, "rb")) == NULL) {
2118 FILE_OP_ERROR(file, "fopen");
2119 return COMPOSE_INSERT_READ_ERROR;
2122 text = GTK_TEXT_VIEW(compose->text);
2123 buffer = gtk_text_view_get_buffer(text);
2124 mark = gtk_text_buffer_get_insert(buffer);
2125 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2127 while (fgets(buf, sizeof(buf), fp) != NULL) {
2129 #if 1 /* FIXME_GTK2 */
2130 const gchar *cur_encoding = conv_get_current_charset_str();
2131 gchar *str = conv_codeset_strdup(buf, cur_encoding, CS_UTF_8);
2135 /* strip <CR> if DOS/Windows file,
2136 replace <CR> with <LF> if Macintosh file. */
2139 if (len > 0 && str[len - 1] != '\n') {
2141 if (str[len] == '\r') str[len] = '\n';
2143 gtk_text_buffer_insert(buffer, &iter, str, -1);
2146 #endif /* FIXME_GTK2 */
2152 return COMPOSE_INSERT_INVALID_CHARACTER;
2154 return COMPOSE_INSERT_SUCCESS;
2157 static void compose_attach_append(Compose *compose, const gchar *file,
2158 const gchar *filename,
2159 const gchar *content_type)
2162 gchar *text[N_ATTACH_COLS];
2167 if (!is_file_exist(file)) {
2168 g_warning("File %s doesn't exist\n", file);
2171 if ((size = get_file_size(file)) < 0) {
2172 g_warning("Can't get file size of %s\n", file);
2176 alertpanel_notice(_("File %s is empty."), file);
2179 if ((fp = fopen(file, "rb")) == NULL) {
2180 alertpanel_error(_("Can't read %s."), file);
2185 #if 0 /* NEW COMPOSE GUI */
2186 if (!compose->use_attach) {
2187 GtkItemFactory *ifactory;
2189 ifactory = gtk_item_factory_from_widget(compose->menubar);
2190 menu_set_active(ifactory, "/View/Attachment", TRUE);
2193 ainfo = g_new0(AttachInfo, 1);
2194 ainfo->file = g_strdup(file);
2197 ainfo->content_type = g_strdup(content_type);
2198 if (!strcasecmp(content_type, "message/rfc822")) {
2200 MsgFlags flags = {0, 0};
2203 if (procmime_get_encoding_for_file(file) == ENC_7BIT)
2204 ainfo->encoding = ENC_7BIT;
2206 ainfo->encoding = ENC_8BIT;
2208 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2209 if (msginfo && msginfo->subject)
2210 name = msginfo->subject;
2212 name = g_basename(filename ? filename : file);
2214 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2216 procmsg_msginfo_free(msginfo);
2218 if (!g_strncasecmp(content_type, "text", 4))
2220 procmime_get_encoding_for_file(file);
2222 ainfo->encoding = ENC_BASE64;
2223 ainfo->name = g_strdup
2224 (g_basename(filename ? filename : file));
2227 ainfo->content_type = procmime_get_mime_type(file);
2228 if (!ainfo->content_type) {
2229 ainfo->content_type =
2230 g_strdup("application/octet-stream");
2231 ainfo->encoding = ENC_BASE64;
2232 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
2233 ainfo->encoding = procmime_get_encoding_for_file(file);
2235 ainfo->encoding = ENC_BASE64;
2236 ainfo->name = g_strdup(g_basename(filename ? filename : file));
2240 text[COL_MIMETYPE] = ainfo->content_type;
2241 text[COL_SIZE] = to_human_readable(size);
2242 text[COL_NAME] = ainfo->name;
2244 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2245 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2249 static void compose_use_signing(Compose *compose, gboolean use_signing)
2251 GtkItemFactory *ifactory;
2252 GtkWidget *menuitem = NULL;
2254 compose->use_signing = use_signing;
2255 ifactory = gtk_item_factory_from_widget(compose->menubar);
2256 menuitem = gtk_item_factory_get_item
2257 (ifactory, "/Message/Sign");
2258 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2260 compose_update_gnupg_mode_menu_item(compose);
2262 #endif /* USE_GPGME */
2264 #define NEXT_PART_NOT_CHILD(info) \
2266 node = info->node; \
2267 while (node->children) \
2268 node = g_node_last_child(node); \
2269 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2272 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2276 MimeInfo *firsttext = NULL;
2277 MimeInfo *encrypted = NULL;
2280 const gchar *partname = NULL;
2282 mimeinfo = procmime_scan_message(msginfo);
2283 if (!mimeinfo) return;
2285 if (mimeinfo->node->children == NULL) {
2286 procmime_mimeinfo_free_all(mimeinfo);
2290 /* find first content part */
2291 child = (MimeInfo *) mimeinfo->node->children->data;
2292 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2293 child = (MimeInfo *)child->node->children->data;
2295 if (child->type == MIMETYPE_TEXT) {
2297 debug_print("First text part found\n");
2298 } else if (compose->mode == COMPOSE_REEDIT &&
2299 child->type == MIMETYPE_APPLICATION &&
2300 !strcasecmp(child->subtype, "pgp-encrypted")) {
2302 val = alertpanel(_("Encrypted message"),
2303 _("Cannot re-edit an encrypted message. \n"
2304 "Discard encrypted part?"),
2305 _("Yes"), _("No"), NULL);
2306 if (val == G_ALERTDEFAULT)
2307 encrypted = (MimeInfo *)child->node->parent->data;
2310 child = (MimeInfo *) mimeinfo->node->children->data;
2311 while (child != NULL) {
2312 if (child == encrypted) {
2313 /* skip this part of tree */
2314 NEXT_PART_NOT_CHILD(child);
2318 if (child->type == MIMETYPE_MULTIPART) {
2319 /* get the actual content */
2320 child = procmime_mimeinfo_next(child);
2324 if (child == firsttext) {
2325 child = procmime_mimeinfo_next(child);
2329 if ((compose->mode == COMPOSE_REEDIT ||
2330 compose->mode == COMPOSE_FORWARD_INLINE ||
2331 compose->mode == COMPOSE_FORWARD ) &&
2332 (child->type == MIMETYPE_APPLICATION) &&
2333 !strcmp(child->subtype, "pgp-signature")) {
2335 if (compose->mode == COMPOSE_REEDIT) {
2336 compose->gnupg_mode = GNUPG_MODE_DETACH;
2337 compose_use_signing(compose, TRUE);
2340 child = procmime_mimeinfo_next(child);
2343 outfile = procmime_get_tmp_file_name(child);
2344 if (procmime_get_part(outfile, child) < 0)
2345 g_warning("Can't get the part of multipart message.");
2347 gchar *content_type;
2349 content_type = g_strdup_printf("%s/%s", procmime_get_type_str(child->type), child->subtype);
2350 partname = procmime_mimeinfo_get_parameter(child, "name");
2351 if (partname == NULL)
2353 compose_attach_append(compose, outfile,
2354 partname, content_type);
2355 g_free(content_type);
2358 NEXT_PART_NOT_CHILD(child);
2360 procmime_mimeinfo_free_all(mimeinfo);
2364 #define CHAR_BUF_SIZE 8
2365 #undef NEXT_PART_NOT_CHILD
2367 #define GET_CHAR(iter_p, buf, len) \
2369 GtkTextIter end_iter; \
2371 end_iter = *iter_p; \
2372 gtk_text_iter_forward_char(&end_iter); \
2373 tmp = gtk_text_buffer_get_text(textbuf, iter_p, &end_iter, FALSE); \
2375 glong items_read, items_witten; \
2376 GError *error = NULL; \
2377 gunichar *wide_char; \
2378 strncpy2(buf, tmp, CHAR_BUF_SIZE); \
2379 wide_char = g_utf8_to_ucs4(tmp, -1, \
2380 &items_read, &items_witten, \
2382 if (error != NULL) { \
2383 g_warning("%s\n", error->message); \
2384 g_error_free(error); \
2386 len = wide_char && g_unichar_iswide(*wide_char) ? 2 : 1; \
2387 g_free(wide_char); \
2395 #define DISP_WIDTH(len) \
2396 ((len > 2 && conv_get_current_charset() == C_UTF_8) ? 2 : \
2397 (len == 2 && conv_get_current_charset() == C_UTF_8) ? 1 : len)
2399 #define SPACE_CHARS " \t"
2402 static void compose_wrap_line(Compose *compose)
2404 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2405 GtkTextBuffer *textbuf = gtk_text_view_get_buffer(text);
2407 GtkTextIter insert_iter, iter;
2408 gint ch_len, last_ch_len;
2409 gchar cbuf[CHAR_BUF_SIZE], last_ch;
2411 gint p_start, p_end;
2412 gint line_pos, cur_pos;
2413 gint line_len, cur_len;
2414 gboolean line_end, quoted;
2416 text_len = gtk_text_buffer_get_char_count(textbuf);
2417 mark = gtk_text_buffer_get_insert(textbuf);
2418 gtk_text_buffer_get_iter_at_mark(textbuf, &insert_iter, mark);
2419 cur_pos = gtk_text_iter_get_offset(&insert_iter);
2420 GET_CHAR(&insert_iter, cbuf, ch_len);
2421 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2422 GtkTextIter prev_iter;
2424 return; /* on the paragraph mark */
2425 prev_iter = insert_iter;
2426 gtk_text_iter_backward_char(&prev_iter);
2427 GET_CHAR(&prev_iter, cbuf, ch_len);
2428 if (ch_len == 1 && *cbuf == '\n')
2429 return; /* on the paragraph mark */
2432 /* find paragraph start. */
2433 line_end = quoted = FALSE;
2434 for (iter = insert_iter; gtk_text_iter_backward_char(&iter);) {
2435 GET_CHAR(&iter, cbuf, ch_len);
2436 if (ch_len == 1 && *cbuf == '\n') {
2438 return; /* quoted part */
2440 gtk_text_iter_forward_chars(&iter, 2);
2446 && strchr(prefs_common.quote_chars, *cbuf))
2448 else if (ch_len != 1 || !isspace(*(guchar *)cbuf))
2454 p_start = gtk_text_iter_get_offset(&iter);
2456 /* find paragraph end. */
2458 for (iter = insert_iter; gtk_text_iter_forward_char(&iter);) {
2459 GET_CHAR(&iter, cbuf, ch_len);
2460 if (ch_len == 1 && *cbuf == '\n') {
2463 gtk_text_iter_backward_char(&iter);
2468 if (line_end && ch_len == 1 &&
2469 strchr(prefs_common.quote_chars, *cbuf))
2470 return; /* quoted part */
2475 p_end = gtk_text_iter_get_offset(&iter);
2477 if (p_end >= text_len)
2480 if (p_start >= p_end)
2483 line_len = cur_len = 0;
2487 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2488 gboolean space = FALSE;
2490 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cur_pos);
2492 GET_CHAR(&iter, cbuf, ch_len);
2499 if (ch_len == 1 && isspace(*(guchar *)cbuf))
2502 if (ch_len == 1 && *cbuf == '\n') {
2503 gboolean replace = FALSE;
2504 GtkTextIter next_iter = iter;
2506 gtk_text_iter_forward_char(&next_iter);
2508 if (last_ch_len == 1 && !isspace((guchar)last_ch)) {
2509 if (cur_pos + 1 < p_end) {
2510 GET_CHAR(&next_iter, cbuf, ch_len);
2512 !isspace(*(guchar *)cbuf))
2516 gtk_text_buffer_delete(textbuf, &iter, &next_iter);
2518 gtk_text_buffer_insert(textbuf, &iter, " ", 1);
2524 gtk_text_buffer_get_iter_at_offset
2525 (textbuf, &iter, cur_pos);
2530 last_ch_len = ch_len;
2534 line_pos = cur_pos + 1;
2535 line_len = cur_len + ch_len;
2538 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, line_pos);
2540 if (cur_len + ch_len > prefs_common.linewrap_len &&
2543 GtkTextIter prev_iter = iter;
2545 gtk_text_iter_backward_char(&prev_iter);
2547 GET_CHAR(&prev_iter, cbuf, ch_len);
2548 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2549 gtk_text_buffer_delete(textbuf, &prev_iter, &iter);
2559 gtk_text_buffer_insert(textbuf, &iter, "\n", 1);
2563 cur_len = cur_len - line_len + ch_len;
2569 line_pos = cur_pos + 1;
2570 line_len = cur_len + ch_len;
2578 /* Darko: used when I debug wrapping */
2579 void dump_text(GtkTextBuffer textbuf, int pos, int tlen, int breakoncr)
2582 gchar cbuf[CHAR_BUF_SIZE];
2584 printf("%d [", pos);
2585 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, pos);
2586 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter, pos + tlen);
2587 for (; gtk_text_iter_forward_char(&iter) &&
2588 gtk_text_iter_compare(&iter, &end_iter) < 0;)
2589 GET_CHAR(&iter, cbuf, clen);
2590 if (clen < 0) break;
2591 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2593 fwrite(cbuf, clen, 1, stdout);
2601 WAIT_FOR_INDENT_CHAR,
2602 WAIT_FOR_INDENT_CHAR_OR_SPACE
2605 /* return indent length, we allow:
2606 > followed by spaces/tabs
2607 | followed by spaces/tabs
2608 uppercase characters immediately followed by >,
2609 and the repeating sequences of the above */
2610 /* return indent length */
2611 static guint get_indent_length(GtkTextBuffer *textbuf, guint start_pos, guint text_len)
2614 guint i, ch_len, alnum_cnt = 0;
2615 IndentState state = WAIT_FOR_INDENT_CHAR;
2616 gchar cbuf[CHAR_BUF_SIZE];
2620 if (prefs_common.quote_chars == NULL) {
2624 for (i = start_pos; i < text_len; i++) {
2627 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, i);
2628 GET_CHAR(&iter, cbuf, ch_len);
2632 if (cbuf[0] == '\n')
2635 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2636 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2639 case WAIT_FOR_SPACE:
2640 if (is_space == FALSE)
2642 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2644 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2645 if (is_indent == FALSE && is_space == FALSE &&
2646 !isupper((guchar)cbuf[0]))
2648 if (is_space == TRUE) {
2650 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2651 } else if (is_indent == TRUE) {
2653 state = WAIT_FOR_SPACE;
2656 state = WAIT_FOR_INDENT_CHAR;
2659 case WAIT_FOR_INDENT_CHAR:
2660 if (is_indent == FALSE && !isupper((guchar)cbuf[0]))
2662 if (is_indent == TRUE) {
2664 && !strchr(prefs_common.quote_chars, cbuf[0]))
2667 state = WAIT_FOR_SPACE;
2678 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2684 /* insert quotation string when line was wrapped */
2685 static guint ins_quote(GtkTextBuffer *textbuf, GtkTextIter *iter,
2687 guint prev_line_pos, guint text_len,
2693 GtkTextIter iter1, iter2;
2696 gtk_text_buffer_get_iter_at_offset(textbuf, &iter1,
2698 gtk_text_buffer_get_iter_at_offset(textbuf, &iter2,
2699 prev_line_pos + indent_len);
2700 text = gtk_text_buffer_get_text(textbuf, &iter1, &iter2, FALSE);
2701 if (!text) return 0;
2703 gtk_text_buffer_insert(textbuf, iter, text, -1);
2704 ins_len = g_utf8_strlen(text, -1);
2712 /* check if we should join the next line */
2713 static gboolean join_next_line_is_needed(GtkTextBuffer *textbuf,
2714 guint start_pos, guint tlen,
2715 guint prev_ilen, gboolean autowrap)
2717 guint indent_len, ch_len;
2718 gboolean do_join = FALSE;
2719 gchar cbuf[CHAR_BUF_SIZE];
2721 indent_len = get_indent_length(textbuf, start_pos, tlen);
2723 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2725 gtk_text_buffer_get_iter_at_offset(textbuf, &iter,
2726 start_pos + indent_len);
2727 GET_CHAR(&iter, cbuf, ch_len);
2728 if (ch_len > 0 && (cbuf[0] != '\n'))
2735 static void compose_wrap_line_all(Compose *compose)
2737 compose_wrap_line_all_full(compose, FALSE);
2740 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2742 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2743 GtkTextBuffer *textbuf = gtk_text_view_get_buffer(text);
2744 GtkTextIter iter, end_iter;
2746 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2747 gint line_len = 0, cur_len = 0;
2749 gboolean is_new_line = TRUE, do_delete = FALSE;
2751 gboolean linewrap_quote = TRUE;
2752 gboolean set_editable_pos = FALSE;
2753 gint editable_pos = 0;
2754 guint linewrap_len = prefs_common.linewrap_len;
2755 gchar *qfmt = prefs_common.quotemark;
2756 gchar cbuf[CHAR_BUF_SIZE];
2758 tlen = gtk_text_buffer_get_char_count(textbuf);
2760 for (; cur_pos < tlen; cur_pos++) {
2761 /* mark position of new line - needed for quotation wrap */
2764 i_len = get_indent_length(textbuf, cur_pos, tlen);
2766 is_new_line = FALSE;
2770 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cur_pos);
2771 GET_CHAR(&iter, cbuf, ch_len);
2773 /* fix line length for tabs */
2774 if (ch_len == 1 && *cbuf == '\t') {
2776 /* guint tab_width = text->default_tab_width; */
2777 guint tab_width = 8;
2778 guint tab_offset = line_len % tab_width;
2781 line_len += tab_width - tab_offset - 1;
2786 /* we have encountered line break */
2787 if (ch_len == 1 && *cbuf == '\n') {
2789 gchar cb[CHAR_BUF_SIZE];
2791 /* should we join the next line */
2792 if ((autowrap || i_len != cur_len) && do_delete &&
2793 join_next_line_is_needed
2794 (textbuf, cur_pos + 1, tlen, i_len, autowrap))
2799 /* skip delete if it is continuous URL */
2800 if (do_delete && (line_pos - p_pos <= i_len) &&
2801 gtkut_text_buffer_is_uri_string(textbuf, line_pos,
2805 /* should we delete to perform smart wrapping */
2806 if (line_len < linewrap_len && do_delete) {
2807 /* get rid of newline */
2808 gtk_text_buffer_get_iter_at_offset(textbuf,
2812 gtk_text_iter_forward_char(&end_iter);
2813 gtk_text_buffer_delete(textbuf, &iter, &end_iter);
2816 /* if text starts with quote fmt or with
2817 indent string, delete them */
2820 ilen = gtkut_text_buffer_str_compare_n
2821 (textbuf, cur_pos, p_pos, i_len,
2825 gtk_text_iter_forward_chars
2827 gtk_text_buffer_delete(textbuf,
2834 gtk_text_buffer_get_iter_at_offset(textbuf,
2837 GET_CHAR(&iter, cb, clen);
2839 /* insert space if it's alphanumeric */
2840 if ((cur_pos != line_pos) &&
2841 ((clen > 1) || isalnum((guchar)cb[0]))) {
2842 gtk_text_buffer_insert(textbuf, &iter,
2847 /* and start over with current line */
2848 cur_pos = p_pos - 1;
2850 line_len = cur_len = 0;
2854 g_print("after delete l_pos=");
2855 dump_text(text, line_pos, tlen, 1);
2857 /* move beginning of line if we are on LF */
2858 gtk_text_buffer_get_iter_at_offset(textbuf,
2861 GET_CHAR(&iter, cb, clen);
2862 if (clen == 1 && *cb == '\n')
2865 g_print("new line_pos=%d\n", line_pos);
2871 /* mark new line beginning */
2872 line_pos = cur_pos + 1;
2873 line_len = cur_len = 0;
2884 /* possible line break */
2885 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2886 line_pos = cur_pos + 1;
2887 line_len = cur_len + ch_len;
2890 /* are we over wrapping length set in preferences ? */
2891 if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
2895 g_print("should wrap cur_pos=%d ", cur_pos);
2896 dump_text(text, p_pos, tlen, 1);
2897 dump_text(text, line_pos, tlen, 1);
2899 /* force wrapping if it is one long word but not URL */
2900 if (line_pos - p_pos <= i_len)
2901 if (!gtkut_text_buffer_is_uri_string
2902 (textbuf, line_pos, tlen))
2903 line_pos = cur_pos - 1;
2905 g_print("new line_pos=%d\n", line_pos);
2908 gtk_text_buffer_get_iter_at_offset(textbuf,
2911 GET_CHAR(&iter, cbuf, clen);
2913 /* if next character is space delete it */
2914 if (clen == 1 && isspace(*(guchar *)cbuf)) {
2915 if (p_pos + i_len != line_pos ||
2916 !gtkut_text_buffer_is_uri_string
2917 (textbuf, line_pos, tlen)) {
2918 /* workaround for correct cursor
2920 if (set_editable_pos == FALSE) {
2921 GtkTextMark *ins = gtk_text_buffer_get_insert(textbuf);
2922 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, ins);
2923 editable_pos = gtk_text_iter_get_offset(&iter);
2924 if (editable_pos == line_pos)
2925 set_editable_pos = TRUE;
2927 gtk_text_buffer_get_iter_at_offset(textbuf,
2930 gtk_text_buffer_get_iter_at_offset(textbuf,
2933 gtk_text_buffer_delete(textbuf, &iter, &end_iter);
2934 //gtk_stext_set_point(text, line_pos);
2935 //gtk_stext_backward_delete(text, 1);
2944 /* if it is URL at beginning of line don't wrap */
2945 if (p_pos + i_len == line_pos &&
2946 gtkut_text_buffer_is_uri_string(textbuf, line_pos, tlen)) {
2948 g_print("found URL at ");
2949 dump_text(text, line_pos, tlen, 1);
2955 gtk_text_buffer_get_iter_at_offset(textbuf,
2958 gtk_text_buffer_insert(textbuf, &iter, "\n", 1);
2959 //gtk_stext_set_point(text, line_pos);
2960 //gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2961 //gtk_stext_compact_buffer(text);
2964 /* for loop will increase it */
2965 cur_pos = line_pos - 1;
2966 /* start over with current line */
2968 line_len = cur_len = 0;
2969 if (autowrap || i_len > 0)
2974 g_print("after CR insert ");
2975 dump_text(text, line_pos, tlen, 1);
2976 dump_text(text, cur_pos, tlen, 1);
2979 /* should we insert quotation ? */
2980 if (linewrap_quote && i_len) {
2981 /* only if line is not already quoted */
2982 if (!gtkut_text_buffer_str_compare
2983 (textbuf, line_pos, tlen, qfmt)) {
2986 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, line_pos);
2988 if (line_pos - p_pos > i_len) {
2990 (textbuf, &iter, i_len, p_pos,
2995 g_print("after quote insert ");
2996 dump_text(text, line_pos, tlen, 1);
3004 line_pos = cur_pos + 1;
3005 line_len = cur_len + ch_len;
3007 /* advance to next character in buffer */
3011 if (set_editable_pos && editable_pos <= tlen) {
3012 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, editable_pos);
3013 gtk_text_buffer_place_cursor(textbuf, &iter);
3018 #undef CHAR_BUF_SIZE
3020 static void compose_set_title(Compose *compose)
3025 edited = compose->modified ? _(" [Edited]") : "";
3026 if (compose->account && compose->account->address)
3027 str = g_strdup_printf(_("%s - Compose message%s"),
3028 compose->account->address, edited);
3030 str = g_strdup_printf(_("Compose message%s"), edited);
3031 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3036 * compose_current_mail_account:
3038 * Find a current mail account (the currently selected account, or the
3039 * default account, if a news account is currently selected). If a
3040 * mail account cannot be found, display an error message.
3042 * Return value: Mail account, or NULL if not found.
3044 static PrefsAccount *
3045 compose_current_mail_account(void)
3049 if (cur_account && cur_account->protocol != A_NNTP)
3052 ac = account_get_default();
3053 if (!ac || ac->protocol == A_NNTP) {
3054 alertpanel_error(_("Account for sending mail is not specified.\n"
3055 "Please select a mail account before sending."));
3062 static void compose_select_account(Compose *compose, PrefsAccount *account,
3065 GtkItemFactory *ifactory;
3067 g_return_if_fail(account != NULL);
3069 compose->account = account;
3071 compose_set_title(compose);
3073 ifactory = gtk_item_factory_from_widget(compose->menubar);
3075 if (account->protocol == A_NNTP) {
3076 gtk_widget_show(compose->newsgroups_hbox);
3077 gtk_widget_show(compose->newsgroups_entry);
3078 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
3079 compose->use_newsgroups = TRUE;
3081 menu_set_active(ifactory, "/View/To", FALSE);
3082 menu_set_sensitive(ifactory, "/View/To", TRUE);
3083 menu_set_active(ifactory, "/View/Cc", FALSE);
3084 menu_set_sensitive(ifactory, "/View/Cc", TRUE);
3085 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
3087 gtk_widget_hide(compose->newsgroups_hbox);
3088 gtk_widget_hide(compose->newsgroups_entry);
3089 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
3090 gtk_widget_queue_resize(compose->table_vbox);
3091 compose->use_newsgroups = FALSE;
3093 menu_set_active(ifactory, "/View/To", TRUE);
3094 menu_set_sensitive(ifactory, "/View/To", FALSE);
3095 menu_set_active(ifactory, "/View/Cc", TRUE);
3096 menu_set_sensitive(ifactory, "/View/Cc", FALSE);
3097 menu_set_active(ifactory, "/View/Followup to", FALSE);
3098 menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
3101 if (account->set_autocc) {
3102 compose_entry_show(compose, COMPOSE_ENTRY_CC);
3103 if (account->auto_cc && compose->mode != COMPOSE_REEDIT)
3104 compose_entry_set(compose, account->auto_cc,
3107 if (account->set_autobcc) {
3108 compose_entry_show(compose, COMPOSE_ENTRY_BCC);
3109 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
3110 compose_entry_set(compose, account->auto_bcc,
3113 if (account->set_autoreplyto) {
3114 compose_entry_show(compose, COMPOSE_ENTRY_REPLY_TO);
3115 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
3116 compose_entry_set(compose, account->auto_replyto,
3117 COMPOSE_ENTRY_REPLY_TO);
3120 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
3121 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
3122 prefs_common.show_ruler);
3126 if (account->default_sign)
3127 menu_set_active(ifactory, "/Message/Sign", TRUE);
3128 if (account->default_encrypt)
3129 menu_set_active(ifactory, "/Message/Encrypt", TRUE);
3131 activate_gnupg_mode(compose, account);
3132 #endif /* USE_GPGME */
3134 if (!init && compose->mode != COMPOSE_REDIRECT)
3135 compose_insert_sig(compose, TRUE);
3138 gboolean compose_check_for_valid_recipient(Compose *compose) {
3139 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
3140 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
3141 gboolean recipient_found = FALSE;
3145 /* free to and newsgroup list */
3146 slist_free_strings(compose->to_list);
3147 g_slist_free(compose->to_list);
3148 compose->to_list = NULL;
3150 slist_free_strings(compose->newsgroup_list);
3151 g_slist_free(compose->newsgroup_list);
3152 compose->newsgroup_list = NULL;
3154 /* search header entries for to and newsgroup entries */
3155 for (list = compose->header_list; list; list = list->next) {
3158 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
3159 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
3161 if (entry[0] != '\0') {
3162 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
3163 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3164 compose->to_list = address_list_append(compose->to_list, entry);
3165 recipient_found = TRUE;
3168 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
3169 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
3170 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
3171 recipient_found = TRUE;
3178 return recipient_found;
3181 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
3185 if (compose_check_for_valid_recipient(compose) == FALSE) {
3186 alertpanel_error(_("Recipient is not specified."));
3190 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3191 if (*str == '\0' && check_subject == TRUE) {
3194 aval = alertpanel(_("Send"),
3195 _("Subject is empty. Send it anyway?"),
3196 _("Yes"), _("No"), NULL);
3197 if (aval != G_ALERTDEFAULT)
3204 gint compose_send(Compose *compose)
3211 if (compose_check_entries(compose, TRUE) == FALSE)
3214 val = compose_queue(compose, &msgnum, &folder);
3216 alertpanel_error(_("Could not queue message for sending"));
3221 alertpanel_error(_("The message was queued but could not be sent.\nUse \"Send queued messages\" from the main window to retry."));
3225 msgpath = folder_item_fetch_msg(folder, msgnum);
3226 val = procmsg_send_message_queue(msgpath);
3229 folder_item_remove_msg(folder, msgnum);
3231 folder_item_scan(folder);
3236 #if 0 /* compose restructure */
3237 gint compose_send(Compose *compose)
3239 gchar tmp[MAXPATHLEN + 1];
3241 static gboolean lock = FALSE;
3245 g_return_val_if_fail(compose->account != NULL, -1);
3249 if (compose_check_entries(compose, TRUE) == FALSE) {
3254 /* write to temporary file */
3255 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%p",
3256 get_tmp_dir(), G_DIR_SEPARATOR, compose);
3258 if (prefs_common.linewrap_at_send)
3259 compose_wrap_line_all(compose);
3261 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
3266 if (!compose->to_list && !compose->newsgroup_list) {
3267 g_warning("can't get recipient list.");
3273 if (compose->to_list) {
3276 #if 0 /* NEW COMPOSE GUI */
3277 if (compose->account->protocol != A_NNTP)
3278 ac = compose->account;
3280 ac = account_find_from_address(compose->account->address);
3282 if (cur_account && cur_account->protocol != A_NNTP)
3285 ac = account_get_default();
3287 if (!ac || ac->protocol == A_NNTP) {
3288 alertpanel_error(_("Account for sending mail is not specified.\n"
3289 "Please select a mail account before sending."));
3296 ac = compose->account;
3298 ok = send_message(tmp, ac, compose->to_list);
3301 if (ok == 0 && compose->newsgroup_list) {
3302 ok = news_post(FOLDER(compose->account->folder), tmp);
3304 alertpanel_error(_("Error occurred while posting the message to %s ."),
3305 compose->account->nntp_server);
3313 if (compose->mode == COMPOSE_REEDIT) {
3314 compose_remove_reedit_target(compose);
3316 /* save message to outbox */
3317 if (prefs_common.savemsg) {
3320 outbox = account_get_special_folder
3321 (compose->account, F_OUTBOX);
3322 if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
3324 (_("Can't save the message to Sent."));
3334 static gboolean compose_use_attach(Compose *compose)
3336 return gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL;
3339 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3342 gchar buf[BUFFSIZE];
3344 gboolean first_to_address;
3345 gboolean first_cc_address;
3347 ComposeHeaderEntry *headerentry;
3348 const gchar *headerentryname;
3352 debug_print("Writing redirect header\n");
3354 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3355 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3357 first_to_address = TRUE;
3358 first_cc_address = TRUE;
3359 for (list = compose->header_list; list; list = list->next) {
3360 headerentry = ((ComposeHeaderEntry *)list->data);
3361 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3363 if (g_strcasecmp(headerentryname, cc_hdr) == 0
3364 || g_strcasecmp(headerentryname, to_hdr) == 0) {
3365 const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3366 Xstrdup_a(str, entstr, return -1);
3368 if (str[0] != '\0') {
3369 compose_convert_header
3370 (buf, sizeof(buf), str,
3371 strlen("Resent-To") + 2, TRUE);
3372 if (g_strcasecmp(headerentryname, to_hdr) == 0) {
3373 if (first_to_address) {
3374 fprintf(fp, "Resent-To: ");
3375 first_to_address = FALSE;
3380 if (g_strcasecmp(headerentryname, cc_hdr) == 0) {
3381 if (first_cc_address) {
3383 fprintf(fp, "Resent-Cc: ");
3384 first_cc_address = FALSE;
3390 fprintf(fp, "%s", buf);
3394 /* if (!first_address) { */
3401 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3403 gchar buf[BUFFSIZE];
3405 const gchar *entstr;
3406 /* struct utsname utsbuf; */
3408 g_return_val_if_fail(fp != NULL, -1);
3409 g_return_val_if_fail(compose->account != NULL, -1);
3410 g_return_val_if_fail(compose->account->address != NULL, -1);
3413 get_rfc822_date(buf, sizeof(buf));
3414 fprintf(fp, "Resent-Date: %s\n", buf);
3417 if (compose->account->name && *compose->account->name) {
3418 compose_convert_header
3419 (buf, sizeof(buf), compose->account->name,
3420 strlen("From: "), TRUE);
3421 fprintf(fp, "Resent-From: %s <%s>\n",
3422 buf, compose->account->address);
3424 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3427 entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3428 if (*entstr != '\0') {
3429 Xstrdup_a(str, entstr, return -1);
3432 compose_convert_header(buf, sizeof(buf), str,
3433 strlen("Subject: "), FALSE);
3434 fprintf(fp, "Subject: %s\n", buf);
3438 /* Resent-Message-ID */
3439 if (compose->account->gen_msgid) {
3440 compose_generate_msgid(buf, sizeof(buf));
3441 fprintf(fp, "Resent-Message-Id: <%s>\n", buf);
3442 compose->msgid = g_strdup(buf);
3445 compose_redirect_write_headers_from_headerlist(compose, fp);
3447 /* separator between header and body */
3453 static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
3458 gchar buf[BUFFSIZE];
3460 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
3461 FILE_OP_ERROR(file, "fopen");
3465 if ((fdest = fopen(file, "wb")) == NULL) {
3466 FILE_OP_ERROR(file, "fopen");
3471 /* chmod for security */
3472 if (change_file_mode_rw(fdest, file) < 0) {
3473 FILE_OP_ERROR(file, "chmod");
3474 g_warning("can't change file mode\n");
3477 while (procheader_get_one_field_asis(buf, sizeof(buf), fp) != -1) {
3478 /* should filter returnpath, delivered-to */
3479 if (g_strncasecmp(buf, "Return-Path:",
3480 strlen("Return-Path:")) == 0 ||
3481 g_strncasecmp(buf, "Delivered-To:",
3482 strlen("Delivered-To:")) == 0 ||
3483 g_strncasecmp(buf, "Received:",
3484 strlen("Received:")) == 0 ||
3485 g_strncasecmp(buf, "Subject:",
3486 strlen("Subject:")) == 0 ||
3487 g_strncasecmp(buf, "X-UIDL:",
3488 strlen("X-UIDL:")) == 0)
3491 if (fputs(buf, fdest) == -1)
3494 if (!prefs_common.redirect_keep_from) {
3495 if (g_strncasecmp(buf, "From:",
3496 strlen("From:")) == 0) {
3497 fputs(" (by way of ", fdest);
3498 if (compose->account->name
3499 && *compose->account->name) {
3500 compose_convert_header
3502 compose->account->name,
3505 fprintf(fdest, "%s <%s>",
3507 compose->account->address);
3509 fprintf(fdest, "%s",
3510 compose->account->address);
3515 if (fputs("\n", fdest) == -1)
3519 compose_redirect_write_headers(compose, fdest);
3521 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3522 if (fwrite(buf, sizeof(gchar), len, fdest) != len) {
3523 FILE_OP_ERROR(file, "fwrite");
3529 if (fclose(fdest) == EOF) {
3530 FILE_OP_ERROR(file, "fclose");
3546 /* interfaces to rfc2015 to keep out the prefs stuff there.
3547 * returns 0 on success and -1 on error. */
3548 static gint compose_create_signers_list(Compose *compose, GSList **pkey_list)
3550 const gchar *key_id = NULL;
3553 switch (compose->account->sign_key) {
3554 case SIGN_KEY_DEFAULT:
3557 case SIGN_KEY_BY_FROM:
3558 key_id = compose->account->address;
3560 case SIGN_KEY_CUSTOM:
3561 key_id = compose->account->sign_key_id;
3567 key_list = rfc2015_create_signers_list(key_id);
3570 alertpanel_error(_("Could not find any key associated with "
3571 "currently selected key id `%s'."), key_id);
3575 *pkey_list = key_list;
3579 /* clearsign message body text */
3580 static gint compose_clearsign_text(Compose *compose, gchar **text)
3585 tmp_file = get_tmp_file();
3586 if (str_write_to_file(*text, tmp_file) < 0) {
3591 if (compose_create_signers_list(compose, &key_list) < 0 ||
3592 rfc2015_clearsign(tmp_file, key_list) < 0) {
3599 *text = file_read_to_str(tmp_file);
3607 #endif /* USE_GPGME */
3609 static gint compose_write_to_file(Compose *compose, const gchar *file,
3612 GtkTextBuffer *buffer;
3613 GtkTextIter start, end;
3619 const gchar *out_codeset;
3620 EncodingType encoding;
3622 if ((fp = fopen(file, "wb")) == NULL) {
3623 FILE_OP_ERROR(file, "fopen");
3627 /* chmod for security */
3628 if (change_file_mode_rw(fp, file) < 0) {
3629 FILE_OP_ERROR(file, "chmod");
3630 g_warning("can't change file mode\n");
3633 /* get all composed text */
3634 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
3635 gtk_text_buffer_get_start_iter(buffer, &start);
3636 gtk_text_buffer_get_end_iter(buffer, &end);
3637 chars = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
3638 if (is_ascii_str(chars)) {
3641 out_codeset = CS_US_ASCII;
3642 encoding = ENC_7BIT;
3644 const gchar *src_codeset;
3646 out_codeset = conv_get_outgoing_charset_str();
3647 if (!strcasecmp(out_codeset, CS_US_ASCII))
3648 out_codeset = CS_ISO_8859_1;
3650 if (prefs_common.encoding_method == CTE_BASE64)
3651 encoding = ENC_BASE64;
3652 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
3653 encoding = ENC_QUOTED_PRINTABLE;
3654 else if (prefs_common.encoding_method == CTE_8BIT)
3655 encoding = ENC_8BIT;
3657 encoding = procmime_get_encoding_for_charset(out_codeset);
3661 compose->use_signing && !compose->gnupg_mode &&
3662 encoding == ENC_8BIT)
3663 encoding = ENC_BASE64;
3667 #if 0 /* FIXME_GTK2 */
3668 src_codeset = conv_get_current_charset_str();
3669 /* if current encoding is US-ASCII, set it the same as
3670 outgoing one to prevent code conversion failure */
3671 if (!strcasecmp(src_codeset, CS_US_ASCII))
3672 src_codeset = out_codeset;
3673 #else /* FIXME_GTK2 */
3674 src_codeset = CS_UTF_8;
3675 #endif /* FIXME_GTK2 */
3677 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3678 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3680 buf = conv_codeset_strdup(