2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2005 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <glib/gi18n.h>
28 #include <gdk/gdkkeysyms.h>
29 #include <gtk/gtkmain.h>
30 #include <gtk/gtkmenu.h>
31 #include <gtk/gtkmenuitem.h>
32 #include <gtk/gtkitemfactory.h>
33 #include <gtk/gtkcheckmenuitem.h>
34 #include <gtk/gtkoptionmenu.h>
35 #include <gtk/gtkwidget.h>
36 #include <gtk/gtkvpaned.h>
37 #include <gtk/gtkentry.h>
38 #include <gtk/gtkeditable.h>
39 #include <gtk/gtkwindow.h>
40 #include <gtk/gtksignal.h>
41 #include <gtk/gtkvbox.h>
42 #include <gtk/gtkcontainer.h>
43 #include <gtk/gtkhandlebox.h>
44 #include <gtk/gtktoolbar.h>
45 #include <gtk/gtktable.h>
46 #include <gtk/gtkhbox.h>
47 #include <gtk/gtklabel.h>
48 #include <gtk/gtkscrolledwindow.h>
49 #include <gtk/gtktreeview.h>
50 #include <gtk/gtkliststore.h>
51 #include <gtk/gtktreeselection.h>
52 #include <gtk/gtktreemodel.h>
54 #include <gtk/gtkdnd.h>
55 #include <gtk/gtkclipboard.h>
60 #include <sys/types.h>
64 /* #include <sys/utsname.h> */
71 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
77 #include "mainwindow.h"
79 #include "addressbook.h"
80 #include "folderview.h"
83 #include "stock_pixmap.h"
84 #include "send_message.h"
87 #include "customheader.h"
88 #include "prefs_common.h"
89 #include "prefs_account.h"
93 #include "procheader.h"
95 #include "statusbar.h"
98 #include "quoted-printable.h"
101 #include "gtkutils.h"
103 #include "alertpanel.h"
104 #include "manage_window.h"
105 #include "gtkshruler.h"
107 #include "addr_compl.h"
108 #include "quote_fmt.h"
109 #include "template.h"
111 #include "foldersel.h"
124 #define N_ATTACH_COLS (N_COL_COLUMNS)
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;
164 COMPOSE_QUIT_EDITING,
165 COMPOSE_KEEP_EDITING,
167 } ComposeDraftAction;
171 COMPOSE_WRITE_FOR_SEND,
172 COMPOSE_WRITE_FOR_STORE
175 #define B64_LINE_SIZE 57
176 #define B64_BUFFSIZE 77
178 #define MAX_REFERENCES_LEN 999
180 static GdkColor quote_color = {0, 0, 0, 0xbfff};
182 static GList *compose_list = NULL;
184 Compose *compose_generic_new (PrefsAccount *account,
187 GPtrArray *attach_files,
188 GList *listAddress );
190 static Compose *compose_create (PrefsAccount *account,
193 static GtkWidget *compose_account_option_menu_create
195 static void compose_set_template_menu (Compose *compose);
196 static void compose_template_apply (Compose *compose,
199 static void compose_destroy (Compose *compose);
201 static void compose_entries_set (Compose *compose,
202 const gchar *mailto);
203 static gint compose_parse_header (Compose *compose,
205 static gchar *compose_parse_references (const gchar *ref,
208 static gchar *compose_quote_fmt (Compose *compose,
214 static void compose_reply_set_entry (Compose *compose,
220 followup_and_reply_to);
221 static void compose_reedit_set_entry (Compose *compose,
223 static void compose_insert_sig (Compose *compose,
225 static gchar *compose_get_signature_str (Compose *compose);
226 static ComposeInsertResult compose_insert_file (Compose *compose,
228 static void compose_attach_append (Compose *compose,
231 const gchar *content_type);
232 static void compose_attach_parts (Compose *compose,
234 static void compose_wrap_line (Compose *compose);
235 static void compose_wrap_line_all (Compose *compose);
236 static void compose_wrap_line_all_full (Compose *compose,
238 static void compose_set_title (Compose *compose);
239 static void compose_select_account (Compose *compose,
240 PrefsAccount *account,
243 static PrefsAccount *compose_current_mail_account(void);
244 /* static gint compose_send (Compose *compose); */
245 static gboolean compose_check_for_valid_recipient
247 static gboolean compose_check_entries (Compose *compose,
248 gboolean check_subject);
249 static gint compose_write_to_file (Compose *compose,
252 static gint compose_write_body_to_file (Compose *compose,
254 static gint compose_remove_reedit_target (Compose *compose);
255 void compose_remove_draft (Compose *compose);
256 static gint compose_queue (Compose *compose,
259 static gint compose_queue_sub (Compose *compose,
262 gboolean check_subject);
263 static void compose_add_attachments (Compose *compose,
265 static gchar *compose_get_header (Compose *compose);
267 static void compose_convert_header (gchar *dest,
271 gboolean addr_field);
273 static void compose_attach_info_free (AttachInfo *ainfo);
274 static void compose_attach_remove_selected (Compose *compose);
276 static void compose_attach_property (Compose *compose);
277 static void compose_attach_property_create (gboolean *cancelled);
278 static void attach_property_ok (GtkWidget *widget,
279 gboolean *cancelled);
280 static void attach_property_cancel (GtkWidget *widget,
281 gboolean *cancelled);
282 static gint attach_property_delete_event (GtkWidget *widget,
284 gboolean *cancelled);
285 static gboolean attach_property_key_pressed (GtkWidget *widget,
287 gboolean *cancelled);
289 static void compose_exec_ext_editor (Compose *compose);
290 static gint compose_exec_ext_editor_real (const gchar *file);
291 static gboolean compose_ext_editor_kill (Compose *compose);
292 static void compose_input_cb (gpointer data,
294 GdkInputCondition condition);
295 static void compose_set_ext_editor_sensitive (Compose *compose,
298 static void compose_undo_state_changed (UndoMain *undostruct,
303 static void compose_create_header_entry (Compose *compose);
304 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
305 static void compose_update_priority_menu_item(Compose * compose);
307 static void compose_add_field_list ( Compose *compose,
308 GList *listAddress );
310 /* callback functions */
312 static gboolean compose_edit_size_alloc (GtkEditable *widget,
313 GtkAllocation *allocation,
314 GtkSHRuler *shruler);
315 static void account_activated (GtkMenuItem *menuitem,
317 static void attach_selected (GtkTreeView *tree_view,
318 GtkTreePath *tree_path,
319 GtkTreeViewColumn *column,
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(GtkWidget *widget,
423 static void compose_update_privacy_system_menu_item(Compose * compose);
424 static void activate_privacy_system (Compose *compose,
425 PrefsAccount *account);
426 static void compose_use_signing(Compose *compose, gboolean use_signing);
427 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
428 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
430 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
432 static void compose_set_priority_cb (gpointer data,
436 static void compose_attach_drag_received_cb (GtkWidget *widget,
437 GdkDragContext *drag_context,
440 GtkSelectionData *data,
444 static void compose_insert_drag_received_cb (GtkWidget *widget,
445 GdkDragContext *drag_context,
448 GtkSelectionData *data,
452 static void compose_header_drag_received_cb (GtkWidget *widget,
453 GdkDragContext *drag_context,
456 GtkSelectionData *data,
461 static gboolean compose_drag_drop (GtkWidget *widget,
462 GdkDragContext *drag_context,
464 guint time, gpointer user_data);
466 static void to_activated (GtkWidget *widget,
468 static void newsgroups_activated (GtkWidget *widget,
470 static void cc_activated (GtkWidget *widget,
472 static void bcc_activated (GtkWidget *widget,
474 static void replyto_activated (GtkWidget *widget,
476 static void followupto_activated (GtkWidget *widget,
478 static void subject_activated (GtkWidget *widget,
482 static void text_inserted (GtkTextBuffer *buffer,
487 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
488 gboolean to_all, gboolean to_ml,
490 gboolean followup_and_reply_to,
493 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
494 ComposeHeaderEntry *headerentry);
495 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
497 ComposeHeaderEntry *headerentry);
499 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
501 static void compose_allow_user_actions (Compose *compose, gboolean allow);
504 static void compose_check_all (Compose *compose);
505 static void compose_highlight_all (Compose *compose);
506 static void compose_check_backwards (Compose *compose);
507 static void compose_check_forwards_go (Compose *compose);
510 static gint compose_defer_auto_save_draft (Compose *compose);
511 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
513 static void compose_close (Compose *compose);
515 static GtkItemFactoryEntry compose_popup_entries[] =
517 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
518 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
519 {N_("/---"), NULL, NULL, 0, "<Separator>"},
520 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
523 static GtkItemFactoryEntry compose_entries[] =
525 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
526 {N_("/_Message/_Send"), "<control>Return",
527 compose_send_cb, 0, NULL},
528 {N_("/_Message/Send _later"), "<shift><control>S",
529 compose_send_later_cb, 0, NULL},
530 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
531 {N_("/_Message/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
532 {N_("/_Message/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
533 {N_("/_Message/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
534 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
535 {N_("/_Message/_Save"),
536 "<control>S", compose_draft_cb, COMPOSE_KEEP_EDITING, NULL},
537 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
538 {N_("/_Message/_Close"), "<control>W", compose_close_cb, 0, NULL},
540 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
541 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
542 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
543 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
544 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
545 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
546 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
547 {N_("/_Edit/Paste as _quotation"),
548 NULL, compose_paste_as_quote_cb, 0, NULL},
549 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
550 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
551 {N_("/_Edit/A_dvanced/Move a character backward"),
553 compose_advanced_action_cb,
554 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
556 {N_("/_Edit/A_dvanced/Move a character forward"),
558 compose_advanced_action_cb,
559 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
561 {N_("/_Edit/A_dvanced/Move a word backward"),
563 compose_advanced_action_cb,
564 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
566 {N_("/_Edit/A_dvanced/Move a word forward"),
568 compose_advanced_action_cb,
569 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
571 {N_("/_Edit/A_dvanced/Move to beginning of line"),
572 NULL, /* "<control>A" */
573 compose_advanced_action_cb,
574 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
576 {N_("/_Edit/A_dvanced/Move to end of line"),
578 compose_advanced_action_cb,
579 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
581 {N_("/_Edit/A_dvanced/Move to previous line"),
583 compose_advanced_action_cb,
584 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
586 {N_("/_Edit/A_dvanced/Move to next line"),
588 compose_advanced_action_cb,
589 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
591 {N_("/_Edit/A_dvanced/Delete a character backward"),
593 compose_advanced_action_cb,
594 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
596 {N_("/_Edit/A_dvanced/Delete a character forward"),
598 compose_advanced_action_cb,
599 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
601 {N_("/_Edit/A_dvanced/Delete a word backward"),
602 NULL, /* "<control>W" */
603 compose_advanced_action_cb,
604 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
606 {N_("/_Edit/A_dvanced/Delete a word forward"),
607 NULL, /* "<alt>D", */
608 compose_advanced_action_cb,
609 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
611 {N_("/_Edit/A_dvanced/Delete line"),
613 compose_advanced_action_cb,
614 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
616 {N_("/_Edit/A_dvanced/Delete entire line"),
618 compose_advanced_action_cb,
619 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
621 {N_("/_Edit/A_dvanced/Delete to end of line"),
623 compose_advanced_action_cb,
624 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
626 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
627 {N_("/_Edit/_Wrap current paragraph"),
628 "<control>L", compose_wrap_line, 0, NULL},
629 {N_("/_Edit/Wrap all long _lines"),
630 "<control><alt>L", compose_wrap_line_all, 0, NULL},
631 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
632 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
633 {N_("/_Edit/Edit with e_xternal editor"),
634 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
636 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
637 {N_("/_Spelling/_Check all or check selection"),
638 NULL, compose_check_all, 0, NULL},
639 {N_("/_Spelling/_Highlight all misspelled words"),
640 NULL, compose_highlight_all, 0, NULL},
641 {N_("/_Spelling/Check _backwards misspelled word"),
642 NULL, compose_check_backwards , 0, NULL},
643 {N_("/_Spelling/_Forward to next misspelled word"),
644 NULL, compose_check_forwards_go, 0, NULL},
645 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
646 {N_("/_Spelling/_Spelling Configuration"),
647 NULL, NULL, 0, "<Branch>"},
649 {N_("/_Options"), NULL, NULL, 0, "<Branch>"},
650 {N_("/_Options/Privacy System"), NULL, NULL, 0, "<Branch>"},
651 {N_("/_Options/Privacy System/None"), NULL, NULL, 0, "<RadioItem>"},
652 {N_("/_Options/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
653 {N_("/_Options/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
654 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
655 {N_("/_Options/_Priority"), NULL, NULL, 0, "<Branch>"},
656 {N_("/_Options/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
657 {N_("/_Options/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Options/Priority/Highest"},
658 {N_("/_Options/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Options/Priority/Highest"},
659 {N_("/_Options/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Options/Priority/Highest"},
660 {N_("/_Options/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Options/Priority/Highest"},
661 {N_("/_Options/---"), NULL, NULL, 0, "<Separator>"},
662 {N_("/_Options/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
663 {N_("/_Options/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
664 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
665 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
666 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
667 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
668 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
669 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
670 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
673 static GtkTargetEntry compose_mime_types[] =
675 {"text/uri-list", 0, 0},
676 {"text/plain", 0, 0},
680 static gboolean compose_put_existing_to_front(MsgInfo *info)
682 GList *compose_list = compose_get_compose_list();
686 for (elem = compose_list; elem != NULL && elem->data != NULL;
688 Compose *c = (Compose*)elem->data;
690 if (!c->targetinfo || !c->targetinfo->msgid ||
694 if (!strcmp(c->targetinfo->msgid, info->msgid)) {
695 gtkut_window_popup(c->window);
703 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
704 GPtrArray *attach_files)
706 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
709 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
711 return compose_generic_new(account, NULL, item, NULL, NULL);
714 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
716 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
719 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
720 GPtrArray *attach_files, GList *listAddress )
723 GtkTextView *textview;
724 GtkTextBuffer *textbuf;
726 GtkItemFactory *ifactory;
728 if (item && item->prefs && item->prefs->enable_default_account)
729 account = account_find_from_id(item->prefs->default_account);
731 if (!account) account = cur_account;
732 g_return_val_if_fail(account != NULL, NULL);
734 compose = compose_create(account, COMPOSE_NEW);
735 ifactory = gtk_item_factory_from_widget(compose->menubar);
737 compose->replyinfo = NULL;
738 compose->fwdinfo = NULL;
740 textview = GTK_TEXT_VIEW(compose->text);
741 textbuf = gtk_text_view_get_buffer(textview);
743 undo_block(compose->undostruct);
745 if (item && item->prefs && item->prefs->enable_default_dictionary &&
747 gtkaspell_change_dict(compose->gtkaspell,
748 item->prefs->default_dictionary);
751 if (account->auto_sig)
752 compose_insert_sig(compose, FALSE);
753 gtk_text_buffer_get_start_iter(textbuf, &iter);
754 gtk_text_buffer_place_cursor(textbuf, &iter);
756 if (account->protocol != A_NNTP) {
757 if (mailto && *mailto != '\0') {
758 compose_entries_set(compose, mailto);
760 } else if (item && item->prefs->enable_default_to) {
761 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
762 compose_entry_mark_default_to(compose, item->prefs->default_to);
764 if (item && item->ret_rcpt) {
765 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
769 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
772 * CLAWS: just don't allow return receipt request, even if the user
773 * may want to send an email. simple but foolproof.
775 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
777 compose_add_field_list( compose, listAddress );
783 for (i = 0; i < attach_files->len; i++) {
784 file = g_ptr_array_index(attach_files, i);
785 compose_attach_append(compose, file, file, NULL);
789 compose_show_first_last_header(compose, TRUE);
791 /* Set save folder */
792 if (item && item->prefs && item->prefs->save_copy_to_folder) {
793 gchar *folderidentifier;
795 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
796 folderidentifier = folder_item_get_identifier(item);
797 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
798 g_free(folderidentifier);
801 gtk_widget_grab_focus(compose->header_last->entry);
803 undo_unblock(compose->undostruct);
805 if (prefs_common.auto_exteditor)
806 compose_exec_ext_editor(compose);
812 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
813 const gchar *followupto, gchar * to)
817 if (!account) account = cur_account;
818 g_return_val_if_fail(account != NULL, NULL);
819 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
821 compose = compose_create(account, COMPOSE_NEW);
823 if (prefs_common.auto_sig)
824 compose_insert_sig(compose);
825 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
826 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
828 compose_entry_append(compose, to, COMPOSE_TO);
829 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
830 gtk_widget_grab_focus(compose->subject_entry);
836 void compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
841 g_return_if_fail(msginfo_list != NULL);
843 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
844 g_return_if_fail(msginfo != NULL);
846 list_len = g_slist_length(msginfo_list);
850 compose_reply(msginfo, prefs_common.reply_with_quote,
851 FALSE, prefs_common.default_reply_list, FALSE, body);
853 case COMPOSE_REPLY_WITH_QUOTE:
854 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, body);
856 case COMPOSE_REPLY_WITHOUT_QUOTE:
857 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
859 case COMPOSE_REPLY_TO_SENDER:
860 compose_reply(msginfo, prefs_common.reply_with_quote,
861 FALSE, FALSE, TRUE, body);
863 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
864 compose_followup_and_reply_to(msginfo,
865 prefs_common.reply_with_quote,
868 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
869 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, body);
871 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
872 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
874 case COMPOSE_REPLY_TO_ALL:
875 compose_reply(msginfo, prefs_common.reply_with_quote,
876 TRUE, FALSE, FALSE, body);
878 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
879 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, body);
881 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
882 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
884 case COMPOSE_REPLY_TO_LIST:
885 compose_reply(msginfo, prefs_common.reply_with_quote,
886 FALSE, TRUE, FALSE, body);
888 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
889 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, body);
891 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
892 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
894 case COMPOSE_FORWARD:
895 if (prefs_common.forward_as_attachment) {
896 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
899 compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
903 case COMPOSE_FORWARD_INLINE:
904 /* check if we reply to more than one Message */
906 compose_forward(NULL, msginfo, FALSE, body, FALSE);
909 /* more messages FALL THROUGH */
910 case COMPOSE_FORWARD_AS_ATTACH:
911 compose_forward_multiple(NULL, msginfo_list);
913 case COMPOSE_REDIRECT:
914 compose_redirect(NULL, msginfo);
917 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
921 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
922 gboolean to_ml, gboolean to_sender,
925 compose_generic_reply(msginfo, quote, to_all, to_ml,
926 to_sender, FALSE, body);
929 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
934 compose_generic_reply(msginfo, quote, to_all, FALSE,
935 to_sender, TRUE, body);
938 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
939 gboolean to_all, gboolean to_ml,
941 gboolean followup_and_reply_to,
944 GtkItemFactory *ifactory;
946 PrefsAccount *account = NULL;
947 PrefsAccount *reply_account;
948 GtkTextView *textview;
949 GtkTextBuffer *textbuf;
953 g_return_if_fail(msginfo != NULL);
954 g_return_if_fail(msginfo->folder != NULL);
956 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
958 g_return_if_fail(account != NULL);
960 if (to_sender && account->protocol == A_NNTP &&
961 !followup_and_reply_to) {
963 account_find_from_address(account->address);
965 reply_account = compose_current_mail_account();
969 reply_account = account;
971 compose = compose_create(account, COMPOSE_REPLY);
972 ifactory = gtk_item_factory_from_widget(compose->menubar);
974 menu_set_active(ifactory, "/Options/Remove references", FALSE);
975 menu_set_sensitive(ifactory, "/Options/Remove references", TRUE);
977 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
978 if (!compose->replyinfo)
979 compose->replyinfo = procmsg_msginfo_copy(msginfo);
981 if (msginfo->folder && msginfo->folder->ret_rcpt)
982 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
984 /* Set save folder */
985 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
986 gchar *folderidentifier;
988 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
989 folderidentifier = folder_item_get_identifier(msginfo->folder);
990 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
991 g_free(folderidentifier);
994 if (compose_parse_header(compose, msginfo) < 0) return;
995 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
996 to_sender, followup_and_reply_to);
997 compose_show_first_last_header(compose, TRUE);
999 textview = (GTK_TEXT_VIEW(compose->text));
1000 textbuf = gtk_text_view_get_buffer(textview);
1002 undo_block(compose->undostruct);
1004 if (msginfo->folder && msginfo->folder->prefs &&
1005 msginfo->folder->prefs &&
1006 msginfo->folder->prefs->enable_default_dictionary &&
1008 gtkaspell_change_dict(compose->gtkaspell,
1009 msginfo->folder->prefs->default_dictionary);
1015 if (prefs_common.quotemark && *prefs_common.quotemark)
1016 qmark = prefs_common.quotemark;
1020 compose_quote_fmt(compose, compose->replyinfo,
1021 prefs_common.quotefmt,
1025 if (account->auto_sig)
1026 compose_insert_sig(compose, FALSE);
1028 cursor_pos = quote_fmt_get_cursor_pos();
1029 gtk_text_buffer_get_start_iter(textbuf, &iter);
1030 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cursor_pos);
1031 gtk_text_buffer_place_cursor(textbuf, &iter);
1033 if (quote && prefs_common.linewrap_quote)
1034 compose_wrap_line_all(compose);
1036 gtk_widget_grab_focus(compose->text);
1038 undo_unblock(compose->undostruct);
1040 if (prefs_common.auto_exteditor)
1041 compose_exec_ext_editor(compose);
1044 #define INSERT_FW_HEADER(var, hdr) \
1045 if (msginfo->var && *msginfo->var) { \
1046 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1047 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1048 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1051 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1052 gboolean as_attach, const gchar *body,
1053 gboolean no_extedit)
1056 GtkTextView *textview;
1057 GtkTextBuffer *textbuf;
1060 g_return_val_if_fail(msginfo != NULL, NULL);
1061 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1064 !(account = compose_guess_forward_account_from_msginfo
1066 account = cur_account;
1068 compose = compose_create(account, COMPOSE_FORWARD);
1070 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1071 if (!compose->fwdinfo)
1072 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1074 if (msginfo->subject && *msginfo->subject) {
1075 gchar *buf, *buf2, *p;
1077 buf = p = g_strdup(msginfo->subject);
1078 p += subject_get_prefix_length(p);
1079 memmove(buf, p, strlen(p) + 1);
1081 buf2 = g_strdup_printf("Fw: %s", buf);
1082 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1088 textview = GTK_TEXT_VIEW(compose->text);
1089 textbuf = gtk_text_view_get_buffer(textview);
1094 msgfile = procmsg_get_message_file_path(msginfo);
1095 if (!is_file_exist(msgfile))
1096 g_warning("%s: file not exist\n", msgfile);
1098 compose_attach_append(compose, msgfile, msgfile,
1104 MsgInfo *full_msginfo;
1106 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1108 full_msginfo = procmsg_msginfo_copy(msginfo);
1110 if (prefs_common.fw_quotemark &&
1111 *prefs_common.fw_quotemark)
1112 qmark = prefs_common.fw_quotemark;
1116 compose_quote_fmt(compose, full_msginfo,
1117 prefs_common.fw_quotefmt,
1119 compose_attach_parts(compose, msginfo);
1121 procmsg_msginfo_free(full_msginfo);
1124 if (account->auto_sig)
1125 compose_insert_sig(compose, FALSE);
1127 if (prefs_common.linewrap_quote)
1128 compose_wrap_line_all(compose);
1130 gtk_text_buffer_get_start_iter(textbuf, &iter);
1131 gtk_text_buffer_place_cursor(textbuf, &iter);
1133 #if 0 /* NEW COMPOSE GUI */
1134 if (account->protocol != A_NNTP)
1135 gtk_widget_grab_focus(compose->to_entry);
1137 gtk_widget_grab_focus(compose->newsgroups_entry);
1139 gtk_widget_grab_focus(compose->header_last->entry);
1141 if (!no_extedit && prefs_common.auto_exteditor)
1142 compose_exec_ext_editor(compose);
1145 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1146 gchar *folderidentifier;
1148 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1149 folderidentifier = folder_item_get_identifier(msginfo->folder);
1150 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1151 g_free(folderidentifier);
1157 #undef INSERT_FW_HEADER
1159 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1162 GtkTextView *textview;
1163 GtkTextBuffer *textbuf;
1168 g_return_val_if_fail(msginfo_list != NULL, NULL);
1170 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1171 if (((MsgInfo *)msginfo->data)->folder == NULL)
1174 /* guess account from first selected message */
1176 !(account = compose_guess_forward_account_from_msginfo
1177 (msginfo_list->data)))
1178 account = cur_account;
1180 g_return_val_if_fail(account != NULL, NULL);
1182 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1183 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1184 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1187 compose = compose_create(account, COMPOSE_FORWARD);
1189 textview = GTK_TEXT_VIEW(compose->text);
1190 textbuf = gtk_text_view_get_buffer(textview);
1192 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1193 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1194 if (!is_file_exist(msgfile))
1195 g_warning("%s: file not exist\n", msgfile);
1197 compose_attach_append(compose, msgfile, msgfile,
1202 if (account->auto_sig)
1203 compose_insert_sig(compose, FALSE);
1205 if (prefs_common.linewrap_quote)
1206 compose_wrap_line_all(compose);
1208 gtk_text_buffer_get_start_iter(textbuf, &iter);
1209 gtk_text_buffer_place_cursor(textbuf, &iter);
1211 gtk_widget_grab_focus(compose->header_last->entry);
1213 #if 0 /* NEW COMPOSE GUI */
1214 if (account->protocol != A_NNTP)
1215 gtk_widget_grab_focus(compose->to_entry);
1217 gtk_widget_grab_focus(compose->newsgroups_entry);
1223 void compose_reedit(MsgInfo *msginfo)
1226 PrefsAccount *account = NULL;
1227 GtkTextView *textview;
1228 GtkTextBuffer *textbuf;
1232 gchar buf[BUFFSIZE];
1233 gboolean use_signing = FALSE;
1234 gboolean use_encryption = FALSE;
1235 gchar *privacy_system = NULL;
1237 g_return_if_fail(msginfo != NULL);
1238 g_return_if_fail(msginfo->folder != NULL);
1240 if (compose_put_existing_to_front(msginfo))
1243 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1244 gchar queueheader_buf[BUFFSIZE];
1247 /* Select Account from queue headers */
1248 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1249 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1250 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1251 account = account_find_from_id(id);
1253 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1254 sizeof(queueheader_buf), "NAID:")) {
1255 id = atoi(&queueheader_buf[strlen("NAID:")]);
1256 account = account_find_from_id(id);
1258 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1259 sizeof(queueheader_buf), "MAID:")) {
1260 id = atoi(&queueheader_buf[strlen("MAID:")]);
1261 account = account_find_from_id(id);
1263 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1264 sizeof(queueheader_buf), "S:")) {
1265 account = account_find_from_address(queueheader_buf);
1267 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1268 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1269 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1270 use_signing = param;
1273 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1274 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1275 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1276 use_encryption = param;
1278 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1279 sizeof(queueheader_buf), "X-Sylpheed-Privacy-System:")) {
1280 privacy_system = g_strdup(&queueheader_buf[strlen("X-Sylpheed-Privacy-System:")]);
1282 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1283 sizeof(queueheader_buf), "X-Priority: ")) {
1284 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1285 compose->priority = param;
1288 account = msginfo->folder->folder->account;
1290 if (!account && prefs_common.reedit_account_autosel) {
1291 gchar from[BUFFSIZE];
1292 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1293 extract_address(from);
1294 account = account_find_from_address(from);
1297 if (!account) account = cur_account;
1298 g_return_if_fail(account != NULL);
1300 compose = compose_create(account, COMPOSE_REEDIT);
1301 compose->privacy_system = privacy_system;
1302 compose_use_signing(compose, use_signing);
1303 compose_use_encryption(compose, use_encryption);
1304 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1306 if (msginfo->folder->stype == F_QUEUE
1307 || msginfo->folder->stype == F_DRAFT) {
1308 gchar queueheader_buf[BUFFSIZE];
1310 /* Set message save folder */
1311 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1314 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1315 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1316 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1320 if (compose_parse_header(compose, msginfo) < 0) return;
1321 compose_reedit_set_entry(compose, msginfo);
1323 textview = GTK_TEXT_VIEW(compose->text);
1324 textbuf = gtk_text_view_get_buffer(textview);
1325 mark = gtk_text_buffer_get_insert(textbuf);
1326 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1328 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1329 G_CALLBACK(compose_changed_cb),
1332 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1333 g_warning("Can't get text part\n");
1335 while (fgets(buf, sizeof(buf), fp) != NULL) {
1337 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1342 compose_attach_parts(compose, msginfo);
1344 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1345 G_CALLBACK(compose_changed_cb),
1348 gtk_widget_grab_focus(compose->text);
1350 if (prefs_common.auto_exteditor)
1351 compose_exec_ext_editor(compose);
1354 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1358 GtkItemFactory *ifactory;
1361 g_return_val_if_fail(msginfo != NULL, NULL);
1364 account = account_get_reply_account(msginfo,
1365 prefs_common.reply_account_autosel);
1366 g_return_val_if_fail(account != NULL, NULL);
1368 compose = compose_create(account, COMPOSE_REDIRECT);
1369 ifactory = gtk_item_factory_from_widget(compose->menubar);
1371 compose->replyinfo = NULL;
1372 compose->fwdinfo = NULL;
1374 compose_show_first_last_header(compose, TRUE);
1376 gtk_widget_grab_focus(compose->header_last->entry);
1378 filename = procmsg_get_message_file_path(msginfo);
1379 if (filename == NULL)
1382 compose->redirect_filename = filename;
1384 /* Set save folder */
1385 item = msginfo->folder;
1386 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1387 gchar *folderidentifier;
1389 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1390 folderidentifier = folder_item_get_identifier(item);
1391 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1392 g_free(folderidentifier);
1395 compose_attach_parts(compose, msginfo);
1397 if (msginfo->subject)
1398 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1400 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1402 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1403 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
1405 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1406 menu_set_sensitive(ifactory, "/Add...", FALSE);
1407 menu_set_sensitive(ifactory, "/Remove", FALSE);
1408 menu_set_sensitive(ifactory, "/Properties...", FALSE);
1410 ifactory = gtk_item_factory_from_widget(compose->menubar);
1411 menu_set_sensitive(ifactory, "/Message/Save", FALSE);
1412 menu_set_sensitive(ifactory, "/Message/Insert file", FALSE);
1413 menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
1414 menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
1415 menu_set_sensitive(ifactory, "/Edit", FALSE);
1416 menu_set_sensitive(ifactory, "/Options", FALSE);
1417 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1418 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1420 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1421 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1422 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1423 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1424 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1425 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1426 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1431 GList *compose_get_compose_list(void)
1433 return compose_list;
1436 void compose_entry_append(Compose *compose, const gchar *address,
1437 ComposeEntryType type)
1441 if (!address || *address == '\0') return;
1443 #if 0 /* NEW COMPOSE GUI */
1446 entry = GTK_ENTRY(compose->cc_entry);
1449 entry = GTK_ENTRY(compose->bcc_entry);
1451 case COMPOSE_NEWSGROUPS:
1452 entry = GTK_ENTRY(compose->newsgroups_entry);
1456 entry = GTK_ENTRY(compose->to_entry);
1460 text = gtk_entry_get_text(entry);
1462 gtk_entry_append_text(entry, ", ");
1463 gtk_entry_append_text(entry, address);
1471 header = N_("Bcc:");
1473 case COMPOSE_REPLYTO:
1474 header = N_("Reply-To:");
1476 case COMPOSE_NEWSGROUPS:
1477 header = N_("Newsgroups:");
1479 case COMPOSE_FOLLOWUPTO:
1480 header = N_( "Followup-To:");
1487 header = prefs_common.trans_hdr ? gettext(header) : header;
1489 compose_add_header_entry(compose, header, (gchar *)address);
1492 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1494 static GtkStyle *bold_style = NULL;
1495 static GdkColor bold_color;
1499 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1500 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1501 if (gtk_entry_get_text(entry) &&
1502 !g_utf8_collate(gtk_entry_get_text(entry), mailto)) {
1503 gtk_widget_ensure_style(GTK_WIDGET(entry));
1505 PangoFontDescription *font_desc = NULL;
1506 gtkut_convert_int_to_gdk_color
1507 (prefs_common.color_new, &bold_color);
1508 bold_style = gtk_style_copy(gtk_widget_get_style
1509 (GTK_WIDGET(entry)));
1511 font_desc = pango_font_description_from_string
1514 if (bold_style->font_desc)
1515 pango_font_description_free
1516 (bold_style->font_desc);
1517 bold_style->font_desc = font_desc;
1519 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1521 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1526 void compose_toolbar_cb(gint action, gpointer data)
1528 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1529 Compose *compose = (Compose*)toolbar_item->parent;
1531 g_return_if_fail(compose != NULL);
1535 compose_send_cb(compose, 0, NULL);
1538 compose_send_later_cb(compose, 0, NULL);
1541 compose_draft_cb(compose, COMPOSE_QUIT_EDITING, NULL);
1544 compose_insert_file_cb(compose, 0, NULL);
1547 compose_attach_cb(compose, 0, NULL);
1550 compose_insert_sig(compose, FALSE);
1553 compose_ext_editor_cb(compose, 0, NULL);
1555 case A_LINEWRAP_CURRENT:
1556 compose_wrap_line(compose);
1558 case A_LINEWRAP_ALL:
1559 compose_wrap_line_all(compose);
1562 compose_address_cb(compose, 0, NULL);
1565 case A_CHECK_SPELLING:
1566 compose_check_all(compose);
1574 static void compose_entries_set(Compose *compose, const gchar *mailto)
1579 gchar *subject = NULL;
1584 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1587 compose_entry_append(compose, to, COMPOSE_TO);
1589 compose_entry_append(compose, cc, COMPOSE_CC);
1591 compose_entry_append(compose, bcc, COMPOSE_BCC);
1593 if (!g_utf8_validate (subject, -1, NULL)) {
1594 temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
1595 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
1598 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1601 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1602 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1606 mark = gtk_text_buffer_get_insert(buffer);
1607 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1609 if (!g_utf8_validate (body, -1, NULL)) {
1610 temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
1611 gtk_text_buffer_insert(buffer, &iter, temp, -1);
1614 gtk_text_buffer_insert(buffer, &iter, body, -1);
1616 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1626 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1628 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1629 {"Cc:", NULL, TRUE},
1630 {"References:", NULL, FALSE},
1631 {"Bcc:", NULL, TRUE},
1632 {"Newsgroups:", NULL, TRUE},
1633 {"Followup-To:", NULL, TRUE},
1634 {"List-Post:", NULL, FALSE},
1635 {"X-Priority:", NULL, FALSE},
1636 {NULL, NULL, FALSE}};
1652 g_return_val_if_fail(msginfo != NULL, -1);
1654 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1655 procheader_get_header_fields(fp, hentry);
1658 if (hentry[H_REPLY_TO].body != NULL) {
1659 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1660 compose->replyto = hentry[H_REPLY_TO].body;
1661 hentry[H_REPLY_TO].body = NULL;
1663 if (hentry[H_CC].body != NULL) {
1664 conv_unmime_header_overwrite(hentry[H_CC].body);
1665 compose->cc = hentry[H_CC].body;
1666 hentry[H_CC].body = NULL;
1668 if (hentry[H_REFERENCES].body != NULL) {
1669 if (compose->mode == COMPOSE_REEDIT)
1670 compose->references = hentry[H_REFERENCES].body;
1672 compose->references = compose_parse_references
1673 (hentry[H_REFERENCES].body, msginfo->msgid);
1674 g_free(hentry[H_REFERENCES].body);
1676 hentry[H_REFERENCES].body = NULL;
1678 if (hentry[H_BCC].body != NULL) {
1679 if (compose->mode == COMPOSE_REEDIT) {
1680 conv_unmime_header_overwrite(hentry[H_BCC].body);
1681 compose->bcc = hentry[H_BCC].body;
1683 g_free(hentry[H_BCC].body);
1684 hentry[H_BCC].body = NULL;
1686 if (hentry[H_NEWSGROUPS].body != NULL) {
1687 conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
1688 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1689 hentry[H_NEWSGROUPS].body = NULL;
1691 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1692 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1693 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1694 hentry[H_FOLLOWUP_TO].body = NULL;
1696 if (hentry[H_LIST_POST].body != NULL) {
1699 extract_address(hentry[H_LIST_POST].body);
1700 if (hentry[H_LIST_POST].body[0] != '\0') {
1701 scan_mailto_url(hentry[H_LIST_POST].body,
1702 &to, NULL, NULL, NULL, NULL);
1704 g_free(compose->ml_post);
1705 compose->ml_post = to;
1708 g_free(hentry[H_LIST_POST].body);
1709 hentry[H_LIST_POST].body = NULL;
1712 /* CLAWS - X-Priority */
1713 if (compose->mode == COMPOSE_REEDIT)
1714 if (hentry[H_X_PRIORITY].body != NULL) {
1717 priority = atoi(hentry[H_X_PRIORITY].body);
1718 g_free(hentry[H_X_PRIORITY].body);
1720 hentry[H_X_PRIORITY].body = NULL;
1722 if (priority < PRIORITY_HIGHEST ||
1723 priority > PRIORITY_LOWEST)
1724 priority = PRIORITY_NORMAL;
1726 compose->priority = priority;
1729 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1730 compose->inreplyto = g_strdup(msginfo->inreplyto);
1731 else if (compose->mode != COMPOSE_REEDIT &&
1732 msginfo->msgid && *msginfo->msgid) {
1733 compose->inreplyto = g_strdup(msginfo->msgid);
1735 if (!compose->references) {
1736 if (msginfo->inreplyto && *msginfo->inreplyto)
1737 compose->references =
1738 g_strdup_printf("<%s>\n\t<%s>",
1742 compose->references =
1743 g_strconcat("<", msginfo->msgid, ">",
1751 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1753 GSList *ref_id_list, *cur;
1757 ref_id_list = references_list_append(NULL, ref);
1758 if (!ref_id_list) return NULL;
1759 if (msgid && *msgid)
1760 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1765 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1766 /* "<" + Message-ID + ">" + CR+LF+TAB */
1767 len += strlen((gchar *)cur->data) + 5;
1769 if (len > MAX_REFERENCES_LEN) {
1770 /* remove second message-ID */
1771 if (ref_id_list && ref_id_list->next &&
1772 ref_id_list->next->next) {
1773 g_free(ref_id_list->next->data);
1774 ref_id_list = g_slist_remove
1775 (ref_id_list, ref_id_list->next->data);
1777 slist_free_strings(ref_id_list);
1778 g_slist_free(ref_id_list);
1785 new_ref = g_string_new("");
1786 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1787 if (new_ref->len > 0)
1788 g_string_append(new_ref, "\n\t");
1789 g_string_append_printf(new_ref, "<%s>", (gchar *)cur->data);
1792 slist_free_strings(ref_id_list);
1793 g_slist_free(ref_id_list);
1795 new_ref_str = new_ref->str;
1796 g_string_free(new_ref, FALSE);
1801 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1802 const gchar *fmt, const gchar *qmark,
1805 static MsgInfo dummyinfo;
1806 gchar *quote_str = NULL;
1810 const gchar *trimmed_body = body;
1813 msginfo = &dummyinfo;
1815 if (qmark != NULL) {
1816 quote_fmt_init(msginfo, NULL, NULL);
1817 quote_fmt_scan_string(qmark);
1820 buf = quote_fmt_get_buffer();
1822 alertpanel_error(_("Quote mark format error."));
1824 Xstrdup_a(quote_str, buf, return NULL)
1827 if (fmt && *fmt != '\0') {
1828 while (trimmed_body && strlen(trimmed_body) > 1
1829 && trimmed_body[0]=='\n')
1832 quote_fmt_init(msginfo, quote_str, trimmed_body);
1833 quote_fmt_scan_string(fmt);
1836 buf = quote_fmt_get_buffer();
1838 alertpanel_error(_("Message reply/forward format error."));
1844 for (p = buf; *p != '\0'; ) {
1845 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1846 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1850 g_signal_handlers_block_by_func(G_OBJECT(buffer),
1851 G_CALLBACK(compose_changed_cb),
1853 g_signal_handlers_block_by_func(G_OBJECT(buffer),
1854 G_CALLBACK(text_inserted),
1857 mark = gtk_text_buffer_get_insert(buffer);
1858 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1860 lastp = strchr(p, '\n');
1861 len = lastp ? lastp - p + 1 : -1;
1863 gtk_text_buffer_insert(buffer, &iter, p, len);
1865 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
1866 G_CALLBACK(compose_changed_cb),
1868 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
1869 G_CALLBACK(text_inserted),
1881 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1882 gboolean to_all, gboolean to_ml,
1884 gboolean followup_and_reply_to)
1886 GSList *cc_list = NULL;
1889 gchar *replyto = NULL;
1890 GHashTable *to_table;
1892 g_return_if_fail(compose->account != NULL);
1893 g_return_if_fail(msginfo != NULL);
1895 if (compose->account->protocol != A_NNTP) {
1896 if (!compose->replyto && to_ml && compose->ml_post
1897 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1898 compose_entry_append(compose,
1901 else if (!(to_all || to_sender)
1903 && msginfo->folder->prefs->enable_default_reply_to) {
1904 compose_entry_append(compose,
1905 msginfo->folder->prefs->default_reply_to,
1908 compose_entry_append(compose,
1909 (compose->replyto && !to_sender)
1910 ? compose->replyto :
1911 msginfo->from ? msginfo->from : "",
1914 if (to_sender || (compose->followup_to &&
1915 !strncmp(compose->followup_to, "poster", 6)))
1916 compose_entry_append
1918 (compose->replyto ? compose->replyto :
1919 msginfo->from ? msginfo->from : ""),
1922 else if (followup_and_reply_to || to_all) {
1923 compose_entry_append
1925 (compose->replyto ? compose->replyto :
1926 msginfo->from ? msginfo->from : ""),
1929 compose_entry_append
1931 compose->followup_to ? compose->followup_to :
1932 compose->newsgroups ? compose->newsgroups : "",
1933 COMPOSE_NEWSGROUPS);
1936 compose_entry_append
1938 compose->followup_to ? compose->followup_to :
1939 compose->newsgroups ? compose->newsgroups : "",
1940 COMPOSE_NEWSGROUPS);
1943 if (msginfo->subject && *msginfo->subject) {
1947 buf = p = g_strdup(msginfo->subject);
1948 p += subject_get_prefix_length(p);
1949 memmove(buf, p, strlen(p) + 1);
1951 buf2 = g_strdup_printf("Re: %s", buf);
1952 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1957 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1959 if (to_ml && compose->ml_post) return;
1960 if (!to_all || compose->account->protocol == A_NNTP) return;
1962 if (compose->replyto) {
1963 Xstrdup_a(replyto, compose->replyto, return);
1964 extract_address(replyto);
1966 if (msginfo->from) {
1967 Xstrdup_a(from, msginfo->from, return);
1968 extract_address(from);
1971 if (replyto && from)
1972 cc_list = address_list_append_with_comments(cc_list, from);
1973 if (to_all && msginfo->folder &&
1974 msginfo->folder->prefs->enable_default_reply_to)
1975 cc_list = address_list_append_with_comments(cc_list,
1976 msginfo->folder->prefs->default_reply_to);
1977 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
1978 cc_list = address_list_append_with_comments(cc_list, compose->cc);
1980 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1982 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
1983 if (compose->account)
1984 g_hash_table_insert(to_table, g_strdup(compose->account->address),
1985 GINT_TO_POINTER(1));
1987 /* remove address on To: and that of current account */
1988 for (cur = cc_list; cur != NULL; ) {
1989 GSList *next = cur->next;
1992 addr = g_strdup(cur->data);
1993 extract_address(addr);
1995 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
1996 cc_list = g_slist_remove(cc_list, cur->data);
1998 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
2002 hash_free_strings(to_table);
2003 g_hash_table_destroy(to_table);
2006 for (cur = cc_list; cur != NULL; cur = cur->next)
2007 compose_entry_append(compose, (gchar *)cur->data,
2009 slist_free_strings(cc_list);
2010 g_slist_free(cc_list);
2015 #define SET_ENTRY(entry, str) \
2018 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2021 #define SET_ADDRESS(type, str) \
2024 compose_entry_append(compose, str, type); \
2027 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2029 g_return_if_fail(msginfo != NULL);
2031 SET_ENTRY(subject_entry, msginfo->subject);
2032 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2033 SET_ADDRESS(COMPOSE_CC, compose->cc);
2034 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2035 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2036 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2037 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2039 compose_update_priority_menu_item(compose);
2040 compose_update_privacy_system_menu_item(compose);
2041 compose_show_first_last_header(compose, TRUE);
2047 static void compose_insert_sig(Compose *compose, gboolean replace)
2049 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2050 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2056 g_return_if_fail(compose->account != NULL);
2058 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2059 G_CALLBACK(compose_changed_cb),
2062 mark = gtk_text_buffer_get_insert(buffer);
2063 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2064 cur_pos = gtk_text_iter_get_offset (&iter);
2066 gtk_text_buffer_get_end_iter(buffer, &iter);
2068 if (replace && compose->sig_str) {
2070 GtkTextIter first_iter, start_iter, end_iter;
2072 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2074 if (compose->sig_str[0] == '\0')
2077 found = gtk_text_iter_forward_search(&first_iter,
2079 GTK_TEXT_SEARCH_TEXT_ONLY,
2080 &start_iter, &end_iter,
2084 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2089 g_free(compose->sig_str);
2090 compose->sig_str = compose_get_signature_str(compose);
2091 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2092 compose->sig_str = g_strdup("");
2094 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2096 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2097 cur_pos = gtk_text_buffer_get_char_count (buffer);
2099 gtk_text_buffer_get_iter_at_offset (buffer, &iter, cur_pos);
2100 gtk_text_buffer_place_cursor (buffer, &iter);
2102 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2103 G_CALLBACK(compose_changed_cb),
2108 static gchar *compose_get_signature_str(Compose *compose)
2110 gchar *sig_body = NULL;
2111 gchar *sig_str = NULL;
2113 g_return_val_if_fail(compose->account != NULL, NULL);
2115 if (!compose->account->sig_path)
2118 if (compose->account->sig_type == SIG_FILE) {
2119 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2120 g_warning("can't open signature file: %s\n",
2121 compose->account->sig_path);
2126 if (compose->account->sig_type == SIG_COMMAND)
2127 sig_body = get_command_output(compose->account->sig_path);
2131 tmp = file_read_to_str(compose->account->sig_path);
2134 sig_body = normalize_newlines(tmp);
2138 if (compose->account->sig_sep)
2139 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2142 sig_str = g_strconcat("\n\n", sig_body, NULL);
2149 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2152 GtkTextBuffer *buffer;
2155 const gchar *cur_encoding;
2156 gchar buf[BUFFSIZE];
2159 gboolean badtxt = FALSE;
2161 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2163 if ((fp = fopen(file, "rb")) == NULL) {
2164 FILE_OP_ERROR(file, "fopen");
2165 return COMPOSE_INSERT_READ_ERROR;
2168 text = GTK_TEXT_VIEW(compose->text);
2169 buffer = gtk_text_view_get_buffer(text);
2170 mark = gtk_text_buffer_get_insert(buffer);
2171 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2173 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2174 G_CALLBACK(text_inserted),
2177 cur_encoding = conv_get_locale_charset_str();
2179 while (fgets(buf, sizeof(buf), fp) != NULL) {
2182 str = conv_codeset_strdup(buf, cur_encoding, CS_INTERNAL);
2185 /* strip <CR> if DOS/Windows file,
2186 replace <CR> with <LF> if Macintosh file. */
2189 if (len > 0 && str[len - 1] != '\n') {
2191 if (str[len] == '\r') str[len] = '\n';
2194 gtk_text_buffer_insert(buffer, &iter, str, -1);
2198 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2199 G_CALLBACK(text_inserted),
2205 return COMPOSE_INSERT_INVALID_CHARACTER;
2207 return COMPOSE_INSERT_SUCCESS;
2210 static void compose_attach_append(Compose *compose, const gchar *file,
2211 const gchar *filename,
2212 const gchar *content_type)
2220 GtkListStore *store;
2223 if (!is_file_exist(file)) {
2224 g_warning("File %s doesn't exist\n", file);
2227 if ((size = get_file_size(file)) < 0) {
2228 g_warning("Can't get file size of %s\n", file);
2232 alertpanel_notice(_("File %s is empty."), file);
2235 if ((fp = fopen(file, "rb")) == NULL) {
2236 alertpanel_error(_("Can't read %s."), file);
2241 #if 0 /* NEW COMPOSE GUI */
2242 if (!compose->use_attach) {
2243 GtkItemFactory *ifactory;
2245 ifactory = gtk_item_factory_from_widget(compose->menubar);
2246 menu_set_active(ifactory, "/View/Attachment", TRUE);
2249 ainfo = g_new0(AttachInfo, 1);
2250 auto_ainfo = g_auto_pointer_new_with_free
2251 (ainfo, (GFreeFunc) compose_attach_info_free);
2252 ainfo->file = g_strdup(file);
2255 ainfo->content_type = g_strdup(content_type);
2256 if (!g_ascii_strcasecmp(content_type, "message/rfc822")) {
2258 MsgFlags flags = {0, 0};
2260 if (procmime_get_encoding_for_text_file(file) == ENC_7BIT)
2261 ainfo->encoding = ENC_7BIT;
2263 ainfo->encoding = ENC_8BIT;
2265 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2266 if (msginfo && msginfo->subject)
2267 name = g_strdup(msginfo->subject);
2269 name = g_path_get_basename(filename ? filename : file);
2271 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2273 procmsg_msginfo_free(msginfo);
2275 if (!g_ascii_strncasecmp(content_type, "text", 4))
2276 ainfo->encoding = procmime_get_encoding_for_text_file(file);
2278 ainfo->encoding = ENC_BASE64;
2279 name = g_path_get_basename(filename ? filename : file);
2280 ainfo->name = g_strdup(name);
2284 ainfo->content_type = procmime_get_mime_type(file);
2285 if (!ainfo->content_type) {
2286 ainfo->content_type =
2287 g_strdup("application/octet-stream");
2288 ainfo->encoding = ENC_BASE64;
2289 } else if (!g_ascii_strncasecmp(ainfo->content_type, "text", 4))
2291 procmime_get_encoding_for_text_file(file);
2293 ainfo->encoding = ENC_BASE64;
2294 name = g_path_get_basename(filename ? filename : file);
2295 ainfo->name = g_strdup(name);
2299 if (!strcmp(ainfo->content_type, "unknown")) {
2300 g_free(ainfo->content_type);
2301 ainfo->content_type = g_strdup("application/octet-stream");
2305 size_text = to_human_readable(size);
2307 store = GTK_LIST_STORE(gtk_tree_view_get_model
2308 (GTK_TREE_VIEW(compose->attach_clist)));
2310 gtk_list_store_append(store, &iter);
2311 gtk_list_store_set(store, &iter,
2312 COL_MIMETYPE, ainfo->content_type,
2313 COL_SIZE, size_text,
2314 COL_NAME, ainfo->name,
2316 COL_AUTODATA, auto_ainfo,
2319 g_auto_pointer_free(auto_ainfo);
2322 static void compose_use_signing(Compose *compose, gboolean use_signing)
2324 GtkItemFactory *ifactory;
2325 GtkWidget *menuitem = NULL;
2327 compose->use_signing = use_signing;
2328 ifactory = gtk_item_factory_from_widget(compose->menubar);
2329 menuitem = gtk_item_factory_get_item
2330 (ifactory, "/Options/Sign");
2331 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2335 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2337 GtkItemFactory *ifactory;
2338 GtkWidget *menuitem = NULL;
2340 compose->use_encryption = use_encryption;
2341 ifactory = gtk_item_factory_from_widget(compose->menubar);
2342 menuitem = gtk_item_factory_get_item
2343 (ifactory, "/Options/Encrypt");
2345 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2349 #define NEXT_PART_NOT_CHILD(info) \
2351 node = info->node; \
2352 while (node->children) \
2353 node = g_node_last_child(node); \
2354 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2357 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2361 MimeInfo *firsttext = NULL;
2362 MimeInfo *encrypted = NULL;
2365 const gchar *partname = NULL;
2367 mimeinfo = procmime_scan_message(msginfo);
2368 if (!mimeinfo) return;
2370 if (mimeinfo->node->children == NULL) {
2371 procmime_mimeinfo_free_all(mimeinfo);
2375 /* find first content part */
2376 child = (MimeInfo *) mimeinfo->node->children->data;
2377 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2378 child = (MimeInfo *)child->node->children->data;
2380 if (child->type == MIMETYPE_TEXT) {
2382 debug_print("First text part found\n");
2383 } else if (compose->mode == COMPOSE_REEDIT &&
2384 child->type == MIMETYPE_APPLICATION &&
2385 !g_ascii_strcasecmp(child->subtype, "pgp-encrypted")) {
2387 val = alertpanel(_("Encrypted message"),
2388 _("Cannot re-edit an encrypted message. \n"
2389 "Discard encrypted part?"),
2390 _("Yes"), _("No"), NULL);
2391 if (val == G_ALERTDEFAULT)
2392 encrypted = (MimeInfo *)child->node->parent->data;
2395 child = (MimeInfo *) mimeinfo->node->children->data;
2396 while (child != NULL) {
2397 if (child == encrypted) {
2398 /* skip this part of tree */
2399 NEXT_PART_NOT_CHILD(child);
2403 if (child->type == MIMETYPE_MULTIPART) {
2404 /* get the actual content */
2405 child = procmime_mimeinfo_next(child);
2409 if (child == firsttext) {
2410 child = procmime_mimeinfo_next(child);
2414 outfile = procmime_get_tmp_file_name(child);
2415 if (procmime_get_part(outfile, child) < 0)
2416 g_warning("Can't get the part of multipart message.");
2418 gchar *content_type;
2420 content_type = procmime_get_content_type_str(child->type, child->subtype);
2421 partname = procmime_mimeinfo_get_parameter(child, "name");
2422 if (partname == NULL)
2424 compose_attach_append(compose, outfile,
2425 partname, content_type);
2426 g_free(content_type);
2429 NEXT_PART_NOT_CHILD(child);
2431 procmime_mimeinfo_free_all(mimeinfo);
2435 #define CHAR_BUF_SIZE 8
2436 #undef NEXT_PART_NOT_CHILD
2439 #define GET_CHAR(iter_p, buf, len) \
2443 uc = gtk_text_iter_get_char(iter_p); \
2445 len = g_unichar_to_utf8(uc, buf) > 1 ? 2 : 1; \
2452 #define DISP_WIDTH(len) \
2454 (len == 2) ? 1 : len)
2456 #define SPACE_CHARS " \t"
2458 static void compose_wrap_line(Compose *compose)
2460 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2461 GtkTextBuffer *textbuf = gtk_text_view_get_buffer(text);
2463 GtkTextIter insert_iter, iter;
2464 gint ch_len, last_ch_len;
2465 gchar cbuf[CHAR_BUF_SIZE], last_ch;
2467 gint p_start, p_end;
2468 gint line_pos, cur_pos;
2469 gint line_len, cur_len;
2470 gboolean line_end, quoted;
2472 text_len = gtk_text_buffer_get_char_count(textbuf);
2473 mark = gtk_text_buffer_get_insert(textbuf);
2474 gtk_text_buffer_get_iter_at_mark(textbuf, &insert_iter, mark);
2475 cur_pos = gtk_text_iter_get_offset(&insert_iter);
2476 GET_CHAR(&insert_iter, cbuf, ch_len);
2477 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2478 GtkTextIter prev_iter;
2480 return; /* on the paragraph mark */
2481 prev_iter = insert_iter;
2482 gtk_text_iter_backward_char(&prev_iter);
2483 GET_CHAR(&prev_iter, cbuf, ch_len);
2484 if (ch_len == 1 && *cbuf == '\n')
2485 return; /* on the paragraph mark */
2488 /* find paragraph start. */
2489 line_end = quoted = FALSE;
2490 for (iter = insert_iter; gtk_text_iter_backward_char(&iter);) {
2491 GET_CHAR(&iter, cbuf, ch_len);
2492 if (ch_len == 1 && *cbuf == '\n') {
2494 return; /* quoted part */
2496 gtk_text_iter_forward_chars(&iter, 2);
2502 && strchr(prefs_common.quote_chars, *cbuf))
2504 else if (ch_len != 1 || !isspace(*(guchar *)cbuf))
2510 p_start = gtk_text_iter_get_offset(&iter);
2512 /* find paragraph end. */
2514 for (iter = insert_iter; gtk_text_iter_forward_char(&iter);) {
2515 GET_CHAR(&iter, cbuf, ch_len);
2516 if (ch_len == 1 && *cbuf == '\n') {
2519 gtk_text_iter_backward_char(&iter);
2524 if (line_end && ch_len == 1 &&
2525 strchr(prefs_common.quote_chars, *cbuf))
2526 return; /* quoted part */
2531 p_end = gtk_text_iter_get_offset(&iter);
2533 if (p_end >= text_len)
2536 if (p_start >= p_end)
2539 line_len = cur_len = 0;
2543 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2544 gboolean space = FALSE;
2546 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cur_pos);
2548 GET_CHAR(&iter, cbuf, ch_len);
2555 if (ch_len == 1 && isspace(*(guchar *)cbuf))
2558 if (ch_len == 1 && *cbuf == '\n') {
2559 gboolean replace = FALSE;
2560 GtkTextIter next_iter = iter;
2562 gtk_text_iter_forward_char(&next_iter);
2564 if (last_ch_len == 1 && !isspace((guchar)last_ch)) {
2565 if (cur_pos + 1 < p_end) {
2566 GET_CHAR(&next_iter, cbuf, ch_len);
2568 !isspace(*(guchar *)cbuf))
2572 gtk_text_buffer_delete(textbuf, &iter, &next_iter);
2574 gtk_text_buffer_insert(textbuf, &iter, " ", 1);
2580 gtk_text_buffer_get_iter_at_offset
2581 (textbuf, &iter, cur_pos);
2586 last_ch_len = ch_len;
2590 line_pos = cur_pos + 1;
2591 line_len = cur_len + DISP_WIDTH(ch_len);
2594 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, line_pos);
2596 if (cur_len + ch_len > prefs_common.linewrap_len &&
2599 GtkTextIter prev_iter = iter;
2601 gtk_text_iter_backward_char(&prev_iter);
2603 GET_CHAR(&prev_iter, cbuf, ch_len);
2604 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2605 gtk_text_buffer_delete(textbuf, &prev_iter, &iter);
2615 gtk_text_buffer_insert(textbuf, &iter, "\n", 1);
2619 cur_len = cur_len - line_len + DISP_WIDTH(ch_len);
2624 cur_len += DISP_WIDTH(ch_len);
2630 /* Darko: used when I debug wrapping */
2631 void dump_text(GtkTextBuffer *textbuf, int pos, int tlen, int breakoncr)
2633 GtkTextIter iter, end_iter;
2635 gchar cbuf[CHAR_BUF_SIZE];
2637 printf("%d [", pos);
2638 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, pos);
2639 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter, pos + tlen);
2640 for (; gtk_text_iter_forward_char(&iter) &&
2641 gtk_text_iter_compare(&iter, &end_iter) < 0; ) {
2642 GET_CHAR(&iter, cbuf, clen);
2643 if (clen < 0) break;
2644 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2646 fwrite(cbuf, clen, 1, stdout);
2654 WAIT_FOR_INDENT_CHAR,
2655 WAIT_FOR_INDENT_CHAR_OR_SPACE
2658 /* return indent length, we allow:
2659 > followed by spaces/tabs
2660 | followed by spaces/tabs
2661 uppercase characters immediately followed by >,
2662 and the repeating sequences of the above */
2663 /* return indent length */
2664 static guint get_indent_length(GtkTextBuffer *textbuf, guint start_pos,
2669 guint ch_len, alnum_cnt = 0;
2670 IndentState state = WAIT_FOR_INDENT_CHAR;
2671 gchar cbuf[CHAR_BUF_SIZE];
2674 gboolean iter_next = TRUE;
2676 if (prefs_common.quote_chars == NULL) {
2680 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, start_pos);
2682 while (iter_next == TRUE) {
2683 GET_CHAR(&iter, cbuf, ch_len);
2687 if (cbuf[0] == '\n')
2690 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2691 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2694 case WAIT_FOR_SPACE:
2695 if (is_space == FALSE)
2697 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2699 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2700 if (is_indent == FALSE && is_space == FALSE &&
2701 !isupper((guchar)cbuf[0]))
2703 if (is_space == TRUE) {
2705 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2706 } else if (is_indent == TRUE) {
2708 state = WAIT_FOR_SPACE;
2711 state = WAIT_FOR_INDENT_CHAR;
2714 case WAIT_FOR_INDENT_CHAR:
2715 if (is_indent == FALSE && !isupper((guchar)cbuf[0]))
2717 if (is_indent == TRUE) {
2719 && !strchr(prefs_common.quote_chars, cbuf[0]))
2722 state = WAIT_FOR_SPACE;
2730 iter_next = gtk_text_iter_forward_char(&iter);
2734 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2740 /* insert quotation string when line was wrapped */
2741 static guint ins_quote(GtkTextBuffer *textbuf, GtkTextIter *iter,
2743 guint prev_line_pos, guint text_len,
2749 GtkTextIter iter1, iter2;
2752 gtk_text_buffer_get_iter_at_offset(textbuf, &iter1,
2754 gtk_text_buffer_get_iter_at_offset(textbuf, &iter2,
2755 prev_line_pos + indent_len);
2756 text = gtk_text_buffer_get_text(textbuf, &iter1, &iter2, FALSE);
2757 if (!text) return 0;
2759 gtk_text_buffer_insert(textbuf, iter, text, -1);
2760 ins_len = g_utf8_strlen(text, -1);
2768 static gboolean is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, guint start_pos)
2772 GtkTextIter end_iter;
2773 if (!compose->account->sig_sep)
2776 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, start_pos+1);
2777 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
2778 start_pos+strlen(compose->account->sig_sep)+1);
2780 if (!strcmp(gtk_text_iter_get_text(&iter, &end_iter),
2781 compose->account->sig_sep)) {
2783 gtk_text_buffer_get_iter_at_offset(textbuf, &iter,
2784 start_pos+strlen(compose->account->sig_sep)+1);
2785 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
2786 start_pos+strlen(compose->account->sig_sep)+2);
2788 if (!strcmp(gtk_text_iter_get_text(&iter, &end_iter),"\n"));
2797 /* check if we should join the next line */
2798 static gboolean join_next_line_is_needed(GtkTextBuffer *textbuf,
2799 guint start_pos, guint tlen,
2800 guint prev_ilen, gboolean autowrap)
2802 guint indent_len, ch_len;
2803 gboolean do_join = FALSE;
2804 gchar cbuf[CHAR_BUF_SIZE];
2806 indent_len = get_indent_length(textbuf, start_pos, tlen);
2808 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2810 gtk_text_buffer_get_iter_at_offset(textbuf, &iter,
2811 start_pos + indent_len);
2812 GET_CHAR(&iter, cbuf, ch_len);
2814 if (ch_len > 0 && (cbuf[0] != '\n'))
2821 static void compose_wrap_line_all(Compose *compose)
2823 compose_wrap_line_all_full(compose, FALSE);
2826 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2828 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2829 GtkTextBuffer *textbuf = gtk_text_view_get_buffer(text);
2830 GtkTextIter iter, end_iter;
2832 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2833 gint line_len = 0, cur_len = 0;
2835 gboolean is_new_line = TRUE, do_delete = FALSE;
2837 gboolean linewrap_quote = prefs_common.linewrap_quote;
2838 gboolean set_editable_pos = FALSE;
2839 gint editable_pos = 0;
2840 guint linewrap_len = prefs_common.linewrap_len;
2841 gchar *qfmt = prefs_common.quotemark;
2842 gchar cbuf[CHAR_BUF_SIZE];
2843 GtkTextMark *cursor_mark = gtk_text_buffer_get_insert(textbuf);
2845 tlen = gtk_text_buffer_get_char_count(textbuf);
2847 for (; cur_pos < tlen; cur_pos++) {
2848 /* mark position of new line - needed for quotation wrap */
2851 i_len = get_indent_length(textbuf, cur_pos, tlen);
2853 is_new_line = FALSE;
2857 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cur_pos);
2858 GET_CHAR(&iter, cbuf, ch_len);
2860 /* fix line length for tabs */
2861 if (ch_len == 1 && *cbuf == '\t') {
2862 guint tab_width = 8;
2863 guint tab_offset = line_len % tab_width;
2865 line_len += tab_width - tab_offset - 1;
2869 /* we have encountered line break */
2870 if (ch_len == 1 && *cbuf == '\n') {
2872 gchar cb[CHAR_BUF_SIZE];
2874 /* should we join the next line */
2875 if ((autowrap || i_len != cur_len) && do_delete &&
2876 !is_sig_separator(compose, textbuf, cur_pos+i_len) &&
2877 join_next_line_is_needed
2878 (textbuf, cur_pos + 1, tlen, i_len, autowrap)) {
2883 /* skip delete if it is continuous URL */
2884 if (do_delete && (line_pos - p_pos <= i_len) &&
2885 gtkut_text_buffer_is_uri_string(textbuf, line_pos,
2889 /* should we delete to perform smart wrapping */
2890 if (line_len < linewrap_len && do_delete) {
2891 /* get rid of newline */
2892 gtk_text_buffer_get_iter_at_offset(textbuf,
2896 gtk_text_iter_forward_char(&end_iter);
2897 gtk_text_buffer_delete(textbuf, &iter, &end_iter);
2900 /* if text starts with quote fmt or with
2901 indent string, delete them */
2904 ilen = gtkut_text_buffer_str_compare_n
2905 (textbuf, cur_pos, p_pos, i_len,
2909 gtk_text_iter_forward_chars
2911 gtk_text_buffer_delete(textbuf,
2918 gtk_text_buffer_get_iter_at_offset(textbuf,
2921 GET_CHAR(&iter, cb, clen);
2923 /* insert space if it's alphanumeric */
2924 if ((cur_pos != line_pos) &&
2925 ((clen > 1) || isalnum((guchar)cb[0]))) {
2926 GtkTextIter cursor_iter;
2927 gboolean go_back = FALSE;
2928 gtk_text_buffer_get_iter_at_mark(textbuf, &cursor_iter, cursor_mark);
2929 if (gtk_text_iter_get_offset(&iter) ==
2930 gtk_text_iter_get_offset(&cursor_iter))
2933 gtk_text_buffer_insert(textbuf, &iter,
2936 gtk_text_buffer_get_iter_at_mark(textbuf, &cursor_iter, cursor_mark);
2937 gtk_text_iter_backward_chars(&cursor_iter, 1);
2938 gtk_text_buffer_place_cursor(textbuf, &cursor_iter);
2943 /* and start over with current line */
2944 cur_pos = p_pos - 1;
2946 line_len = cur_len = 0;
2950 g_print("after delete l_pos=");
2951 dump_text(textbuf, line_pos, tlen, 1);
2953 /* move beginning of line if we are on LF */
2954 gtk_text_buffer_get_iter_at_offset(textbuf,
2957 GET_CHAR(&iter, cb, clen);
2958 if (clen == 1 && *cb == '\n')
2961 g_print("new line_pos=%d\n", line_pos);
2967 /* mark new line beginning */
2968 line_pos = cur_pos + 1;
2969 line_len = cur_len = 0;
2980 /* possible line break */
2981 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2982 line_pos = cur_pos + 1;
2983 line_len = cur_len + DISP_WIDTH(ch_len);
2986 /* are we over wrapping length set in preferences ? */
2987 if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
2991 g_print("should wrap cur_pos=%d ", cur_pos);
2992 dump_text(textbuf, p_pos, tlen, 1);
2993 dump_text(textbuf, line_pos, tlen, 1);
2995 /* force wrapping if it is one long word but not URL */
2996 if (line_pos - p_pos <= i_len)
2997 if (!gtkut_text_buffer_is_uri_string
2998 (textbuf, line_pos, tlen))
2999 line_pos = cur_pos - 1;
3001 g_print("new line_pos=%d\n", line_pos);
3004 gtk_text_buffer_get_iter_at_offset(textbuf,
3007 GET_CHAR(&iter, cbuf, clen);
3009 /* if next character is space delete it */
3010 if (clen == 1 && isspace(*(guchar *)cbuf)) {
3011 if (p_pos + i_len != line_pos ||
3012 !gtkut_text_buffer_is_uri_string
3013 (textbuf, line_pos, tlen)) {
3014 /* workaround for correct cursor
3016 if (set_editable_pos == FALSE) {
3017 GtkTextMark *ins = gtk_text_buffer_get_insert(textbuf);
3018 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, ins);
3019 editable_pos = gtk_text_iter_get_offset(&iter);
3020 if (editable_pos == line_pos)
3021 set_editable_pos = TRUE;
3023 gtk_text_buffer_get_iter_at_offset(textbuf,
3026 gtk_text_buffer_get_iter_at_offset(textbuf,
3029 gtk_text_buffer_delete(textbuf, &iter, &end_iter);
3030 //gtk_stext_set_point(text, line_pos);
3031 //gtk_stext_backward_delete(text, 1);
3040 /* if it is URL at beginning of line don't wrap */
3041 if (p_pos + i_len == line_pos &&
3042 gtkut_text_buffer_is_uri_string(textbuf, line_pos, tlen)) {
3044 g_print("found URL at ");
3045 dump_text(textbuf, line_pos, tlen, 1);
3051 gtk_text_buffer_get_iter_at_offset(textbuf,
3054 gtk_text_buffer_insert(textbuf, &iter, "\n", 1);
3055 //gtk_stext_set_point(text, line_pos);
3056 //gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
3057 //gtk_stext_compact_buffer(text);
3060 /* for loop will increase it */
3061 cur_pos = line_pos - 1;
3062 /* start over with current line */
3064 line_len = cur_len = 0;
3065 if (autowrap || i_len > 0) {
3070 g_print("after CR insert ");
3071 dump_text(textbuf, line_pos, tlen, 1);
3072 dump_text(textbuf, cur_pos, tlen, 1);
3075 /* should we insert quotation ? */
3076 if (linewrap_quote && i_len) {
3077 /* only if line is not already quoted */
3078 if (!gtkut_text_buffer_str_compare
3079 (textbuf, line_pos, tlen, qfmt)) {
3082 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, line_pos);
3084 if (line_pos - p_pos > i_len) {
3086 (textbuf, &iter, i_len, p_pos,
3091 g_print("after quote insert ");
3092 dump_text(textbuf, line_pos, tlen, 1);
3099 /* advance to next character in buffer */
3100 cur_len += DISP_WIDTH(ch_len);
3103 if (set_editable_pos && editable_pos <= tlen) {
3104 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, editable_pos);
3105 gtk_text_buffer_place_cursor(textbuf, &iter);
3110 #undef CHAR_BUF_SIZE
3112 static void compose_set_title(Compose *compose)
3117 edited = compose->modified ? _(" [Edited]") : "";
3118 if (compose->account && compose->account->address)
3119 str = g_strdup_printf(_("%s - Compose message%s"),
3120 compose->account->address, edited);
3122 str = g_strdup_printf(_("Compose message%s"), edited);
3123 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3128 * compose_current_mail_account:
3130 * Find a current mail account (the currently selected account, or the
3131 * default account, if a news account is currently selected). If a
3132 * mail account cannot be found, display an error message.
3134 * Return value: Mail account, or NULL if not found.
3136 static PrefsAccount *
3137 compose_current_mail_account(void)
3141 if (cur_account && cur_account->protocol != A_NNTP)
3144 ac = account_get_default();
3145 if (!ac || ac->protocol == A_NNTP) {
3146 alertpanel_error(_("Account for sending mail is not specified.\n"
3147 "Please select a mail account before sending."));
3154 static void compose_select_account(Compose *compose, PrefsAccount *account,
3157 GtkItemFactory *ifactory;
3159 g_return_if_fail(account != NULL);
3161 compose->account = account;
3163 compose_set_title(compose);
3165 ifactory = gtk_item_factory_from_widget(compose->menubar);
3167 if (account->protocol == A_NNTP) {
3168 gtk_widget_show(compose->newsgroups_hbox);
3169 gtk_widget_show(compose->newsgroups_entry);