2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2004 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtkmain.h>
29 #include <gtk/gtkmenu.h>
30 #include <gtk/gtkmenuitem.h>
31 #include <gtk/gtkitemfactory.h>
32 #include <gtk/gtkcheckmenuitem.h>
33 #include <gtk/gtkoptionmenu.h>
34 #include <gtk/gtkwidget.h>
35 #include <gtk/gtkclist.h>
36 #include <gtk/gtkctree.h>
37 #include <gtk/gtkvpaned.h>
38 #include <gtk/gtkentry.h>
39 #include <gtk/gtkeditable.h>
40 #include <gtk/gtkwindow.h>
41 #include <gtk/gtksignal.h>
42 #include <gtk/gtkvbox.h>
43 #include <gtk/gtkcontainer.h>
44 #include <gtk/gtkhandlebox.h>
45 #include <gtk/gtktoolbar.h>
46 #include <gtk/gtktable.h>
47 #include <gtk/gtkhbox.h>
48 #include <gtk/gtklabel.h>
49 #include <gtk/gtkscrolledwindow.h>
50 #include <gtk/gtktreeview.h>
52 #include <gtk/gtkdnd.h>
57 #include <sys/types.h>
61 /* #include <sys/utsname.h> */
68 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
75 #include "mainwindow.h"
77 #include "addressbook.h"
78 #include "folderview.h"
81 #include "stock_pixmap.h"
82 #include "send_message.h"
85 #include "customheader.h"
86 #include "prefs_common.h"
87 #include "prefs_account.h"
91 #include "procheader.h"
93 #include "statusbar.h"
96 #include "quoted-printable.h"
101 #include "alertpanel.h"
102 #include "manage_window.h"
103 #include "gtkshruler.h"
105 #include "addr_compl.h"
106 #include "quote_fmt.h"
107 #include "template.h"
109 #include "foldersel.h"
113 # include "rfc2015.h"
123 #define N_ATTACH_COLS 3
127 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
128 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
129 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
130 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
131 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
132 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
133 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
134 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
135 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
136 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
137 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
138 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
139 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
140 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
141 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
142 } ComposeCallAdvancedAction;
146 PRIORITY_HIGHEST = 1,
155 COMPOSE_INSERT_SUCCESS,
156 COMPOSE_INSERT_READ_ERROR,
157 COMPOSE_INSERT_INVALID_CHARACTER,
158 COMPOSE_INSERT_NO_FILE
159 } ComposeInsertResult;
161 #define B64_LINE_SIZE 57
162 #define B64_BUFFSIZE 77
164 #define MAX_REFERENCES_LEN 999
166 static GdkColor quote_color = {0, 0, 0, 0xbfff};
168 static GList *compose_list = NULL;
170 Compose *compose_generic_new (PrefsAccount *account,
173 GPtrArray *attach_files,
174 GList *listAddress );
176 static Compose *compose_create (PrefsAccount *account,
179 static GtkWidget *compose_account_option_menu_create
181 static void compose_set_template_menu (Compose *compose);
182 static void compose_template_apply (Compose *compose,
185 static void compose_destroy (Compose *compose);
187 static void compose_entries_set (Compose *compose,
188 const gchar *mailto);
189 static gint compose_parse_header (Compose *compose,
191 static gchar *compose_parse_references (const gchar *ref,
194 static gchar *compose_quote_fmt (Compose *compose,
200 static void compose_reply_set_entry (Compose *compose,
206 followup_and_reply_to);
207 static void compose_reedit_set_entry (Compose *compose,
209 static void compose_insert_sig (Compose *compose,
211 static gchar *compose_get_signature_str (Compose *compose);
212 static ComposeInsertResult compose_insert_file (Compose *compose,
214 static void compose_attach_append (Compose *compose,
217 const gchar *content_type);
218 static void compose_attach_parts (Compose *compose,
220 static void compose_wrap_line (Compose *compose);
221 static void compose_wrap_line_all (Compose *compose);
222 static void compose_wrap_line_all_full (Compose *compose,
224 static void compose_set_title (Compose *compose);
225 static void compose_select_account (Compose *compose,
226 PrefsAccount *account,
229 static PrefsAccount *compose_current_mail_account(void);
230 /* static gint compose_send (Compose *compose); */
231 static gboolean compose_check_for_valid_recipient
233 static gboolean compose_check_entries (Compose *compose,
234 gboolean check_subject);
235 static gint compose_write_to_file (Compose *compose,
238 static gint compose_write_body_to_file (Compose *compose,
240 static gint compose_remove_reedit_target (Compose *compose);
241 void compose_remove_draft (Compose *compose);
242 static gint compose_queue (Compose *compose,
245 static gint compose_queue_sub (Compose *compose,
248 gboolean check_subject);
249 static void compose_write_attach (Compose *compose,
251 static gchar *compose_get_header (Compose *compose,
252 const gchar *charset,
253 EncodingType encoding,
256 static void compose_convert_header (gchar *dest,
260 gboolean addr_field);
261 static void compose_generate_msgid (gchar *buf,
264 static void compose_attach_info_free (AttachInfo *ainfo);
265 static void compose_attach_remove_selected (Compose *compose);
267 static void compose_attach_property (Compose *compose);
268 static void compose_attach_property_create (gboolean *cancelled);
269 static void attach_property_ok (GtkWidget *widget,
270 gboolean *cancelled);
271 static void attach_property_cancel (GtkWidget *widget,
272 gboolean *cancelled);
273 static gint attach_property_delete_event (GtkWidget *widget,
275 gboolean *cancelled);
276 static gboolean attach_property_key_pressed (GtkWidget *widget,
278 gboolean *cancelled);
280 static void compose_exec_ext_editor (Compose *compose);
281 static gint compose_exec_ext_editor_real (const gchar *file);
282 static gboolean compose_ext_editor_kill (Compose *compose);
283 static void compose_input_cb (gpointer data,
285 GdkInputCondition condition);
286 static void compose_set_ext_editor_sensitive (Compose *compose,
289 static void compose_undo_state_changed (UndoMain *undostruct,
294 static gint calc_cursor_xpos (GtkTextView *text,
298 static void compose_create_header_entry (Compose *compose);
299 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
300 static void compose_update_priority_menu_item(Compose * compose);
302 static void compose_add_field_list ( Compose *compose,
303 GList *listAddress );
305 /* callback functions */
307 static gboolean compose_edit_size_alloc (GtkEditable *widget,
308 GtkAllocation *allocation,
309 GtkSHRuler *shruler);
310 static void account_activated (GtkMenuItem *menuitem,
312 static void attach_selected (GtkCList *clist,
317 static gboolean attach_button_pressed (GtkWidget *widget,
318 GdkEventButton *event,
320 static gboolean attach_key_pressed (GtkWidget *widget,
324 static void compose_send_cb (gpointer data,
327 static void compose_send_later_cb (gpointer data,
331 static void compose_draft_cb (gpointer data,
335 static void compose_attach_cb (gpointer data,
338 static void compose_insert_file_cb (gpointer data,
341 static void compose_insert_sig_cb (gpointer data,
345 static void compose_close_cb (gpointer data,
349 static void compose_address_cb (gpointer data,
352 static void compose_template_activate_cb(GtkWidget *widget,
355 static void compose_ext_editor_cb (gpointer data,
359 static gint compose_delete_cb (GtkWidget *widget,
362 static void compose_destroy_cb (GtkWidget *widget,
365 static void compose_undo_cb (Compose *compose);
366 static void compose_redo_cb (Compose *compose);
367 static void compose_cut_cb (Compose *compose);
368 static void compose_copy_cb (Compose *compose);
369 static void compose_paste_cb (Compose *compose);
370 static void compose_paste_as_quote_cb (Compose *compose);
371 static void compose_allsel_cb (Compose *compose);
373 static void compose_advanced_action_cb (Compose *compose,
374 ComposeCallAdvancedAction action);
376 static gboolean compose_grab_focus_cb (GtkWidget *widget,
378 static gboolean compose_grab_focus_before_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);
424 static void compose_use_signing(Compose *compose, gboolean use_signing);
425 static void compose_use_encryption(Compose *compose, gboolean use_encryption);
427 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
429 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
431 static void compose_set_priority_cb (gpointer data,
435 static void compose_attach_drag_received_cb (GtkWidget *widget,
436 GdkDragContext *drag_context,
439 GtkSelectionData *data,
443 static void compose_insert_drag_received_cb (GtkWidget *widget,
444 GdkDragContext *drag_context,
447 GtkSelectionData *data,
453 static void to_activated (GtkWidget *widget,
455 static void newsgroups_activated (GtkWidget *widget,
457 static void cc_activated (GtkWidget *widget,
459 static void bcc_activated (GtkWidget *widget,
461 static void replyto_activated (GtkWidget *widget,
463 static void followupto_activated (GtkWidget *widget,
465 static void subject_activated (GtkWidget *widget,
469 static void text_activated (GtkWidget *widget,
471 static void text_inserted (GtkTextBuffer *buffer,
476 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
477 gboolean to_all, gboolean to_ml,
479 gboolean followup_and_reply_to,
482 gboolean compose_headerentry_changed_cb (GtkWidget *entry,
483 ComposeHeaderEntry *headerentry);
484 gboolean compose_headerentry_key_press_event_cb(GtkWidget *entry,
486 ComposeHeaderEntry *headerentry);
488 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
490 static void compose_allow_user_actions (Compose *compose, gboolean allow);
493 static void compose_check_all (Compose *compose);
494 static void compose_highlight_all (Compose *compose);
495 static void compose_check_backwards (Compose *compose);
496 static void compose_check_forwards_go (Compose *compose);
499 static gboolean compose_send_control_enter (Compose *compose);
500 static gint compose_defer_auto_save_draft (Compose *compose);
501 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
503 static GtkItemFactoryEntry compose_popup_entries[] =
505 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
506 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
507 {N_("/---"), NULL, NULL, 0, "<Separator>"},
508 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
511 static GtkItemFactoryEntry compose_entries[] =
513 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
515 "<control>S", compose_draft_cb, 1, NULL},
516 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
517 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
518 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
519 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
520 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
521 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
523 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
524 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
525 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
526 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
527 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
528 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
529 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
530 {N_("/_Edit/Paste as _quotation"),
531 NULL, compose_paste_as_quote_cb, 0, NULL},
532 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
533 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
534 {N_("/_Edit/A_dvanced/Move a character backward"),
536 compose_advanced_action_cb,
537 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
539 {N_("/_Edit/A_dvanced/Move a character forward"),
541 compose_advanced_action_cb,
542 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
544 {N_("/_Edit/A_dvanced/Move a word backward"),
546 compose_advanced_action_cb,
547 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
549 {N_("/_Edit/A_dvanced/Move a word forward"),
551 compose_advanced_action_cb,
552 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
554 {N_("/_Edit/A_dvanced/Move to beginning of line"),
555 NULL, /* "<control>A" */
556 compose_advanced_action_cb,
557 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
559 {N_("/_Edit/A_dvanced/Move to end of line"),
561 compose_advanced_action_cb,
562 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
564 {N_("/_Edit/A_dvanced/Move to previous line"),
566 compose_advanced_action_cb,
567 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
569 {N_("/_Edit/A_dvanced/Move to next line"),
571 compose_advanced_action_cb,
572 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
574 {N_("/_Edit/A_dvanced/Delete a character backward"),
576 compose_advanced_action_cb,
577 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
579 {N_("/_Edit/A_dvanced/Delete a character forward"),
581 compose_advanced_action_cb,
582 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
584 {N_("/_Edit/A_dvanced/Delete a word backward"),
585 NULL, /* "<control>W" */
586 compose_advanced_action_cb,
587 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
589 {N_("/_Edit/A_dvanced/Delete a word forward"),
590 NULL, /* "<alt>D", */
591 compose_advanced_action_cb,
592 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
594 {N_("/_Edit/A_dvanced/Delete line"),
596 compose_advanced_action_cb,
597 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
599 {N_("/_Edit/A_dvanced/Delete entire line"),
601 compose_advanced_action_cb,
602 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
604 {N_("/_Edit/A_dvanced/Delete to end of line"),
606 compose_advanced_action_cb,
607 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
609 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
610 {N_("/_Edit/_Wrap current paragraph"),
611 "<control>L", compose_wrap_line, 0, NULL},
612 {N_("/_Edit/Wrap all long _lines"),
613 "<control><alt>L", compose_wrap_line_all, 0, NULL},
614 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
615 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
616 {N_("/_Edit/Edit with e_xternal editor"),
617 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
619 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
620 {N_("/_Spelling/_Check all or check selection"),
621 NULL, compose_check_all, 0, NULL},
622 {N_("/_Spelling/_Highlight all misspelled words"),
623 NULL, compose_highlight_all, 0, NULL},
624 {N_("/_Spelling/Check _backwards misspelled word"),
625 NULL, compose_check_backwards , 0, NULL},
626 {N_("/_Spelling/_Forward to next misspelled word"),
627 NULL, compose_check_forwards_go, 0, NULL},
628 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
629 {N_("/_Spelling/_Spelling Configuration"),
630 NULL, NULL, 0, "<Branch>"},
632 #if 0 /* NEW COMPOSE GUI */
633 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
634 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
635 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
636 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
637 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
638 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
639 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
640 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
641 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
642 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
643 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
645 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
646 {N_("/_Message/_Send"), "<control>Return",
647 compose_send_cb, 0, NULL},
648 {N_("/_Message/Send _later"), "<shift><control>S",
649 compose_send_later_cb, 0, NULL},
650 #if 0 /* NEW COMPOSE GUI */
651 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
652 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
653 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
654 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
655 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
656 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
657 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
658 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
659 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
662 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
663 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
664 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
665 {N_("/_Message/Mode"), NULL, NULL, 0, "<Branch>"},
666 {N_("/_Message/Mode/MIME"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_DETACH, "<RadioItem>"},
667 {N_("/_Message/Mode/Inline"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_INLINE, "/Message/Mode/MIME"},
668 #endif /* USE_GPGME */
669 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
670 {N_("/_Message/_Priority"), NULL, NULL, 0, "<Branch>"},
671 {N_("/_Message/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
672 {N_("/_Message/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
673 {N_("/_Message/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
674 {N_("/_Message/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
675 {N_("/_Message/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
676 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
677 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
678 {N_("/_Message/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
679 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
680 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
681 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
682 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
683 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
684 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
685 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
688 static GtkTargetEntry compose_mime_types[] =
690 {"text/uri-list", 0, 0}
693 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
694 GPtrArray *attach_files)
696 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
699 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
701 return compose_generic_new(account, NULL, item, NULL, NULL);
704 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
706 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
709 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
710 GPtrArray *attach_files, GList *listAddress )
713 GtkTextView *textview;
714 GtkTextBuffer *textbuf;
716 GtkItemFactory *ifactory;
718 if (item && item->prefs && item->prefs->enable_default_account)
719 account = account_find_from_id(item->prefs->default_account);
721 if (!account) account = cur_account;
722 g_return_val_if_fail(account != NULL, NULL);
724 compose = compose_create(account, COMPOSE_NEW);
725 ifactory = gtk_item_factory_from_widget(compose->menubar);
727 compose->replyinfo = NULL;
728 compose->fwdinfo = NULL;
730 textview = GTK_TEXT_VIEW(compose->text);
731 textbuf = gtk_text_view_get_buffer(textview);
733 undo_block(compose->undostruct);
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);
992 undo_block(compose->undostruct);
994 if (msginfo->folder && msginfo->folder->prefs &&
995 msginfo->folder->prefs &&
996 msginfo->folder->prefs->enable_default_dictionary &&
998 gtkaspell_change_dict(compose->gtkaspell,
999 msginfo->folder->prefs->default_dictionary);
1005 if (prefs_common.quotemark && *prefs_common.quotemark)
1006 qmark = prefs_common.quotemark;
1010 compose_quote_fmt(compose, compose->replyinfo,
1011 prefs_common.quotefmt,
1015 if (account->auto_sig)
1016 compose_insert_sig(compose, FALSE);
1018 if (quote && prefs_common.linewrap_quote)
1019 compose_wrap_line_all(compose);
1021 cursor_pos = quote_fmt_get_cursor_pos();
1022 gtk_text_buffer_get_start_iter(textbuf, &iter);
1023 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cursor_pos);
1024 gtk_text_buffer_place_cursor(textbuf, &iter);
1026 if (quote && prefs_common.linewrap_quote) {
1027 compose_wrap_line_all(compose);
1028 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), TRUE);
1031 gtk_widget_grab_focus(compose->text);
1033 undo_unblock(compose->undostruct);
1035 if (prefs_common.auto_exteditor)
1036 compose_exec_ext_editor(compose);
1039 #define INSERT_FW_HEADER(var, hdr) \
1040 if (msginfo->var && *msginfo->var) { \
1041 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1042 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1043 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1046 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1047 gboolean as_attach, const gchar *body,
1048 gboolean no_extedit)
1051 GtkTextView *textview;
1052 GtkTextBuffer *textbuf;
1055 g_return_val_if_fail(msginfo != NULL, NULL);
1056 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1059 !(account = compose_guess_forward_account_from_msginfo
1061 account = cur_account;
1063 compose = compose_create(account, COMPOSE_FORWARD);
1065 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1066 if (!compose->fwdinfo)
1067 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1069 if (msginfo->subject && *msginfo->subject) {
1070 gchar *buf, *buf2, *p;
1072 buf = p = g_strdup(msginfo->subject);
1073 p += subject_get_prefix_length(p);
1074 memmove(buf, p, strlen(p) + 1);
1076 buf2 = g_strdup_printf("Fw: %s", buf);
1077 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1083 textview = GTK_TEXT_VIEW(compose->text);
1084 textbuf = gtk_text_view_get_buffer(textview);
1089 msgfile = procmsg_get_message_file_path(msginfo);
1090 if (!is_file_exist(msgfile))
1091 g_warning("%s: file not exist\n", msgfile);
1093 compose_attach_append(compose, msgfile, msgfile,
1099 MsgInfo *full_msginfo;
1101 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1103 full_msginfo = procmsg_msginfo_copy(msginfo);
1105 if (prefs_common.fw_quotemark &&
1106 *prefs_common.fw_quotemark)
1107 qmark = prefs_common.fw_quotemark;
1111 compose_quote_fmt(compose, full_msginfo,
1112 prefs_common.fw_quotefmt,
1114 compose_attach_parts(compose, msginfo);
1116 procmsg_msginfo_free(full_msginfo);
1119 if (account->auto_sig)
1120 compose_insert_sig(compose, FALSE);
1122 if (prefs_common.linewrap_quote)
1123 compose_wrap_line_all(compose);
1125 gtk_text_buffer_get_start_iter(textbuf, &iter);
1126 gtk_text_buffer_place_cursor(textbuf, &iter);
1128 #if 0 /* NEW COMPOSE GUI */
1129 if (account->protocol != A_NNTP)
1130 gtk_widget_grab_focus(compose->to_entry);
1132 gtk_widget_grab_focus(compose->newsgroups_entry);
1134 gtk_widget_grab_focus(compose->header_last->entry);
1136 if (!no_extedit && prefs_common.auto_exteditor)
1137 compose_exec_ext_editor(compose);
1140 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1141 gchar *folderidentifier;
1143 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1144 folderidentifier = folder_item_get_identifier(msginfo->folder);
1145 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1146 g_free(folderidentifier);
1152 #undef INSERT_FW_HEADER
1154 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1157 GtkTextView *textview;
1158 GtkTextBuffer *textbuf;
1163 g_return_val_if_fail(msginfo_list != NULL, NULL);
1165 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1166 if (((MsgInfo *)msginfo->data)->folder == NULL)
1169 /* guess account from first selected message */
1171 !(account = compose_guess_forward_account_from_msginfo
1172 (msginfo_list->data)))
1173 account = cur_account;
1175 g_return_val_if_fail(account != NULL, NULL);
1177 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1178 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1179 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1182 compose = compose_create(account, COMPOSE_FORWARD);
1184 textview = GTK_TEXT_VIEW(compose->text);
1185 textbuf = gtk_text_view_get_buffer(textview);
1187 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1188 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1189 if (!is_file_exist(msgfile))
1190 g_warning("%s: file not exist\n", msgfile);
1192 compose_attach_append(compose, msgfile, msgfile,
1197 if (account->auto_sig)
1198 compose_insert_sig(compose, FALSE);
1200 if (prefs_common.linewrap_quote)
1201 compose_wrap_line_all(compose);
1203 gtk_text_buffer_get_start_iter(textbuf, &iter);
1204 gtk_text_buffer_place_cursor(textbuf, &iter);
1206 gtk_widget_grab_focus(compose->header_last->entry);
1208 #if 0 /* NEW COMPOSE GUI */
1209 if (account->protocol != A_NNTP)
1210 gtk_widget_grab_focus(compose->to_entry);
1212 gtk_widget_grab_focus(compose->newsgroups_entry);
1218 void compose_reedit(MsgInfo *msginfo)
1221 PrefsAccount *account = NULL;
1222 GtkTextView *textview;
1223 GtkTextBuffer *textbuf;
1227 gchar buf[BUFFSIZE];
1229 gboolean use_signing = FALSE;
1230 gboolean use_encryption = FALSE;
1231 gboolean gnupg_mode = FALSE;
1234 g_return_if_fail(msginfo != NULL);
1235 g_return_if_fail(msginfo->folder != NULL);
1237 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1238 gchar queueheader_buf[BUFFSIZE];
1241 /* Select Account from queue headers */
1242 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1243 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1244 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1245 account = account_find_from_id(id);
1247 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1248 sizeof(queueheader_buf), "NAID:")) {
1249 id = atoi(&queueheader_buf[strlen("NAID:")]);
1250 account = account_find_from_id(id);
1252 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1253 sizeof(queueheader_buf), "MAID:")) {
1254 id = atoi(&queueheader_buf[strlen("MAID:")]);
1255 account = account_find_from_id(id);
1257 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1258 sizeof(queueheader_buf), "S:")) {
1259 account = account_find_from_address(queueheader_buf);
1262 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1263 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1264 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1265 use_signing = param;
1268 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1269 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1270 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1271 use_encryption = param;
1273 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1274 sizeof(queueheader_buf), "X-Sylpheed-Gnupg-Mode:")) {
1275 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Gnupg-Mode:")]);
1279 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1280 sizeof(queueheader_buf), "X-Priority: ")) {
1281 param = atoi(&queueheader_buf[strlen("X-Priority: ")]); /* mind the space */
1282 compose->priority = param;
1285 account = msginfo->folder->folder->account;
1287 if (!account && prefs_common.reedit_account_autosel) {
1288 gchar from[BUFFSIZE];
1289 if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1290 extract_address(from);
1291 account = account_find_from_address(from);
1294 if (!account) account = cur_account;
1295 g_return_if_fail(account != NULL);
1297 compose = compose_create(account, COMPOSE_REEDIT);
1299 compose->gnupg_mode = gnupg_mode;
1300 compose_use_signing(compose, use_signing);
1301 compose_use_encryption(compose, use_encryption);
1303 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1305 if (msginfo->folder->stype == F_QUEUE
1306 || msginfo->folder->stype == F_DRAFT) {
1307 gchar queueheader_buf[BUFFSIZE];
1309 /* Set message save folder */
1310 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1313 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1314 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1315 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1319 if (compose_parse_header(compose, msginfo) < 0) return;
1320 compose_reedit_set_entry(compose, msginfo);
1322 textview = GTK_TEXT_VIEW(compose->text);
1323 textbuf = gtk_text_view_get_buffer(textview);
1324 mark = gtk_text_buffer_get_insert(textbuf);
1325 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1327 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1328 G_CALLBACK(compose_changed_cb),
1331 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1332 g_warning("Can't get text part\n");
1334 while (fgets(buf, sizeof(buf), fp) != NULL) {
1336 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1341 compose_attach_parts(compose, msginfo);
1343 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1344 G_CALLBACK(compose_changed_cb),
1347 gtk_widget_grab_focus(compose->text);
1349 if (prefs_common.auto_exteditor)
1350 compose_exec_ext_editor(compose);
1353 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1357 GtkItemFactory *ifactory;
1360 g_return_val_if_fail(msginfo != NULL, NULL);
1363 account = account_get_reply_account(msginfo,
1364 prefs_common.reply_account_autosel);
1365 g_return_val_if_fail(account != NULL, NULL);
1367 compose = compose_create(account, COMPOSE_REDIRECT);
1368 ifactory = gtk_item_factory_from_widget(compose->menubar);
1370 compose->replyinfo = NULL;
1371 compose->fwdinfo = NULL;
1373 compose_show_first_last_header(compose, TRUE);
1375 gtk_widget_grab_focus(compose->header_last->entry);
1377 filename = procmsg_get_message_file(msginfo);
1378 if (filename == NULL)
1381 compose->redirect_filename = filename;
1383 /* Set save folder */
1384 item = msginfo->folder;
1385 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1386 gchar *folderidentifier;
1388 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1389 folderidentifier = folder_item_get_identifier(item);
1390 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1391 g_free(folderidentifier);
1394 compose_attach_parts(compose, msginfo);
1396 if (msginfo->subject)
1397 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1399 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1401 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1402 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), TRUE);
1404 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1405 menu_set_sensitive(ifactory, "/Add...", FALSE);
1406 menu_set_sensitive(ifactory, "/Remove", FALSE);
1407 menu_set_sensitive(ifactory, "/Property...", FALSE);
1409 ifactory = gtk_item_factory_from_widget(compose->menubar);
1410 menu_set_sensitive(ifactory, "/File/Save", FALSE);
1411 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
1412 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
1413 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
1414 menu_set_sensitive(ifactory, "/Edit", FALSE);
1416 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
1417 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
1418 menu_set_sensitive(ifactory, "/Message/Mode/MIME", FALSE);
1419 menu_set_sensitive(ifactory, "/Message/Mode/Inline", FALSE);
1421 menu_set_sensitive(ifactory, "/Message/Priority", FALSE);
1422 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
1423 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1424 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1426 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1427 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1428 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1429 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1430 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1431 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1432 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1437 GList *compose_get_compose_list(void)
1439 return compose_list;
1442 void compose_entry_append(Compose *compose, const gchar *address,
1443 ComposeEntryType type)
1447 if (!address || *address == '\0') return;
1449 #if 0 /* NEW COMPOSE GUI */
1452 entry = GTK_ENTRY(compose->cc_entry);
1455 entry = GTK_ENTRY(compose->bcc_entry);
1457 case COMPOSE_NEWSGROUPS:
1458 entry = GTK_ENTRY(compose->newsgroups_entry);
1462 entry = GTK_ENTRY(compose->to_entry);
1466 text = gtk_entry_get_text(entry);
1468 gtk_entry_append_text(entry, ", ");
1469 gtk_entry_append_text(entry, address);
1477 header = N_("Bcc:");
1479 case COMPOSE_REPLYTO:
1480 header = N_("Reply-To:");
1482 case COMPOSE_NEWSGROUPS:
1483 header = N_("Newsgroups:");
1485 case COMPOSE_FOLLOWUPTO:
1486 header = N_( "Followup-To:");
1493 header = prefs_common.trans_hdr ? gettext(header) : header;
1495 compose_add_header_entry(compose, header, (gchar *)address);
1498 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1500 static GtkStyle *bold_style = NULL;
1501 static GdkColor bold_color;
1505 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1506 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1507 if (gtk_entry_get_text(entry) &&
1508 !g_strcasecmp(gtk_entry_get_text(entry), mailto)) {
1509 gtk_widget_ensure_style(GTK_WIDGET(entry));
1511 PangoFontDescription *font_desc = NULL;
1512 gtkut_convert_int_to_gdk_color
1513 (prefs_common.color_new, &bold_color);
1514 bold_style = gtk_style_copy(gtk_widget_get_style
1515 (GTK_WIDGET(entry)));
1517 font_desc = pango_font_description_from_string
1520 if (bold_style->font_desc)
1521 pango_font_description_free
1522 (bold_style->font_desc);
1523 bold_style->font_desc = font_desc;
1525 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1527 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1532 void compose_toolbar_cb(gint action, gpointer data)
1534 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1535 Compose *compose = (Compose*)toolbar_item->parent;
1537 g_return_if_fail(compose != NULL);
1541 compose_send_cb(compose, 0, NULL);
1544 compose_send_later_cb(compose, 0, NULL);
1547 compose_draft_cb(compose, 0, NULL);
1550 compose_insert_file_cb(compose, 0, NULL);
1553 compose_attach_cb(compose, 0, NULL);
1556 compose_insert_sig(compose, FALSE);
1559 compose_ext_editor_cb(compose, 0, NULL);
1561 case A_LINEWRAP_CURRENT:
1562 compose_wrap_line(compose);
1564 case A_LINEWRAP_ALL:
1565 compose_wrap_line_all(compose);
1568 compose_address_cb(compose, 0, NULL);
1571 case A_CHECK_SPELLING:
1572 compose_check_all(compose);
1580 static void compose_entries_set(Compose *compose, const gchar *mailto)
1585 gchar *subject = NULL;
1588 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1591 compose_entry_append(compose, to, COMPOSE_TO);
1593 compose_entry_append(compose, cc, COMPOSE_CC);
1595 compose_entry_append(compose, bcc, COMPOSE_BCC);
1597 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1599 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1600 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1604 mark = gtk_text_buffer_get_insert(buffer);
1605 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1607 gtk_text_buffer_insert(buffer, &iter, body, -1);
1608 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1618 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1620 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1621 {"Cc:", NULL, TRUE},
1622 {"References:", NULL, FALSE},
1623 {"Bcc:", NULL, TRUE},
1624 {"Newsgroups:", NULL, TRUE},
1625 {"Followup-To:", NULL, TRUE},
1626 {"List-Post:", NULL, FALSE},
1627 {"X-Priority:", NULL, FALSE},
1628 {NULL, NULL, FALSE}};
1644 g_return_val_if_fail(msginfo != NULL, -1);
1646 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1647 procheader_get_header_fields(fp, hentry);
1650 if (hentry[H_REPLY_TO].body != NULL) {
1651 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1652 compose->replyto = hentry[H_REPLY_TO].body;
1653 hentry[H_REPLY_TO].body = NULL;
1655 if (hentry[H_CC].body != NULL) {
1656 conv_unmime_header_overwrite(hentry[H_CC].body);
1657 compose->cc = hentry[H_CC].body;
1658 hentry[H_CC].body = NULL;
1660 if (hentry[H_REFERENCES].body != NULL) {
1661 if (compose->mode == COMPOSE_REEDIT)
1662 compose->references = hentry[H_REFERENCES].body;
1664 compose->references = compose_parse_references
1665 (hentry[H_REFERENCES].body, msginfo->msgid);
1666 g_free(hentry[H_REFERENCES].body);
1668 hentry[H_REFERENCES].body = NULL;
1670 if (hentry[H_BCC].body != NULL) {
1671 if (compose->mode == COMPOSE_REEDIT) {
1672 conv_unmime_header_overwrite(hentry[H_BCC].body);
1673 compose->bcc = hentry[H_BCC].body;
1675 g_free(hentry[H_BCC].body);
1676 hentry[H_BCC].body = NULL;
1678 if (hentry[H_NEWSGROUPS].body != NULL) {
1679 conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
1680 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1681 hentry[H_NEWSGROUPS].body = NULL;
1683 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1684 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1685 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1686 hentry[H_FOLLOWUP_TO].body = NULL;
1688 if (hentry[H_LIST_POST].body != NULL) {
1691 extract_address(hentry[H_LIST_POST].body);
1692 if (hentry[H_LIST_POST].body[0] != '\0') {
1693 scan_mailto_url(hentry[H_LIST_POST].body,
1694 &to, NULL, NULL, NULL, NULL);
1696 g_free(compose->ml_post);
1697 compose->ml_post = to;
1700 g_free(hentry[H_LIST_POST].body);
1701 hentry[H_LIST_POST].body = NULL;
1704 /* CLAWS - X-Priority */
1705 if (compose->mode == COMPOSE_REEDIT)
1706 if (hentry[H_X_PRIORITY].body != NULL) {
1709 priority = atoi(hentry[H_X_PRIORITY].body);
1710 g_free(hentry[H_X_PRIORITY].body);
1712 hentry[H_X_PRIORITY].body = NULL;
1714 if (priority < PRIORITY_HIGHEST ||
1715 priority > PRIORITY_LOWEST)
1716 priority = PRIORITY_NORMAL;
1718 compose->priority = priority;
1721 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1722 compose->inreplyto = g_strdup(msginfo->inreplyto);
1723 else if (compose->mode != COMPOSE_REEDIT &&
1724 msginfo->msgid && *msginfo->msgid) {
1725 compose->inreplyto = g_strdup(msginfo->msgid);
1727 if (!compose->references) {
1728 if (msginfo->inreplyto && *msginfo->inreplyto)
1729 compose->references =
1730 g_strdup_printf("<%s>\n\t<%s>",
1734 compose->references =
1735 g_strconcat("<", msginfo->msgid, ">",
1743 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1745 GSList *ref_id_list, *cur;
1749 ref_id_list = references_list_append(NULL, ref);
1750 if (!ref_id_list) return NULL;
1751 if (msgid && *msgid)
1752 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1757 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1758 /* "<" + Message-ID + ">" + CR+LF+TAB */
1759 len += strlen((gchar *)cur->data) + 5;
1761 if (len > MAX_REFERENCES_LEN) {
1762 /* remove second message-ID */
1763 if (ref_id_list && ref_id_list->next &&
1764 ref_id_list->next->next) {
1765 g_free(ref_id_list->next->data);
1766 ref_id_list = g_slist_remove
1767 (ref_id_list, ref_id_list->next->data);
1769 slist_free_strings(ref_id_list);
1770 g_slist_free(ref_id_list);
1777 new_ref = g_string_new("");
1778 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1779 if (new_ref->len > 0)
1780 g_string_append(new_ref, "\n\t");
1781 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1784 slist_free_strings(ref_id_list);
1785 g_slist_free(ref_id_list);
1787 new_ref_str = new_ref->str;
1788 g_string_free(new_ref, FALSE);
1793 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1794 const gchar *fmt, const gchar *qmark,
1797 static MsgInfo dummyinfo;
1798 gchar *quote_str = NULL;
1802 const gchar *trimmed_body = body;
1805 msginfo = &dummyinfo;
1807 if (qmark != NULL) {
1808 quote_fmt_init(msginfo, NULL, NULL);
1809 quote_fmt_scan_string(qmark);
1812 buf = quote_fmt_get_buffer();
1814 alertpanel_error(_("Quote mark format error."));
1816 Xstrdup_a(quote_str, buf, return NULL)
1819 if (fmt && *fmt != '\0') {
1820 while (trimmed_body && strlen(trimmed_body) > 1
1821 && trimmed_body[0]=='\n')
1824 quote_fmt_init(msginfo, quote_str, trimmed_body);
1825 quote_fmt_scan_string(fmt);
1828 buf = quote_fmt_get_buffer();
1830 alertpanel_error(_("Message reply/forward format error."));
1836 for (p = buf; *p != '\0'; ) {
1837 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1838 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1842 g_signal_handlers_block_by_func(G_OBJECT(buffer),
1843 G_CALLBACK(compose_changed_cb),
1845 g_signal_handlers_block_by_func(G_OBJECT(buffer),
1846 G_CALLBACK(text_inserted),
1849 mark = gtk_text_buffer_get_insert(buffer);
1850 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1852 lastp = strchr(p, '\n');
1853 len = lastp ? lastp - p + 1 : -1;
1855 gtk_text_buffer_insert(buffer, &iter, p, len);
1857 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
1858 G_CALLBACK(compose_changed_cb),
1860 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
1861 G_CALLBACK(text_inserted),
1873 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1874 gboolean to_all, gboolean to_ml,
1876 gboolean followup_and_reply_to)
1878 GSList *cc_list = NULL;
1881 gchar *replyto = NULL;
1882 GHashTable *to_table;
1884 g_return_if_fail(compose->account != NULL);
1885 g_return_if_fail(msginfo != NULL);
1887 if (compose->account->protocol != A_NNTP) {
1888 if (!compose->replyto && to_ml && compose->ml_post
1889 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1890 compose_entry_append(compose,
1893 else if (!(to_all || to_sender)
1895 && msginfo->folder->prefs->enable_default_reply_to) {
1896 compose_entry_append(compose,
1897 msginfo->folder->prefs->default_reply_to,
1900 compose_entry_append(compose,
1901 (compose->replyto && !to_sender)
1902 ? compose->replyto :
1903 msginfo->from ? msginfo->from : "",
1906 if (to_sender || (compose->followup_to &&
1907 !strncmp(compose->followup_to, "poster", 6)))
1908 compose_entry_append
1910 (compose->replyto ? compose->replyto :
1911 msginfo->from ? msginfo->from : ""),
1914 else if (followup_and_reply_to || to_all) {
1915 compose_entry_append
1917 (compose->replyto ? compose->replyto :
1918 msginfo->from ? msginfo->from : ""),
1921 compose_entry_append
1923 compose->followup_to ? compose->followup_to :
1924 compose->newsgroups ? compose->newsgroups : "",
1925 COMPOSE_NEWSGROUPS);
1928 compose_entry_append
1930 compose->followup_to ? compose->followup_to :
1931 compose->newsgroups ? compose->newsgroups : "",
1932 COMPOSE_NEWSGROUPS);
1935 if (msginfo->subject && *msginfo->subject) {
1939 buf = p = g_strdup(msginfo->subject);
1940 p += subject_get_prefix_length(p);
1941 memmove(buf, p, strlen(p) + 1);
1943 buf2 = g_strdup_printf("Re: %s", buf);
1944 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1949 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1951 if (to_ml && compose->ml_post) return;
1952 if (!to_all || compose->account->protocol == A_NNTP) return;
1954 if (compose->replyto) {
1955 Xstrdup_a(replyto, compose->replyto, return);
1956 extract_address(replyto);
1958 if (msginfo->from) {
1959 Xstrdup_a(from, msginfo->from, return);
1960 extract_address(from);
1963 if (replyto && from)
1964 cc_list = address_list_append_with_comments(cc_list, from);
1965 if (to_all && msginfo->folder &&
1966 msginfo->folder->prefs->enable_default_reply_to)
1967 cc_list = address_list_append_with_comments(cc_list,
1968 msginfo->folder->prefs->default_reply_to);
1969 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
1970 cc_list = address_list_append_with_comments(cc_list, compose->cc);
1972 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1974 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
1975 if (compose->account)
1976 g_hash_table_insert(to_table, g_strdup(compose->account->address),
1977 GINT_TO_POINTER(1));
1979 /* remove address on To: and that of current account */
1980 for (cur = cc_list; cur != NULL; ) {
1981 GSList *next = cur->next;
1984 addr = g_strdup(cur->data);
1985 extract_address(addr);
1987 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
1988 cc_list = g_slist_remove(cc_list, cur->data);
1990 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
1994 hash_free_strings(to_table);
1995 g_hash_table_destroy(to_table);
1998 for (cur = cc_list; cur != NULL; cur = cur->next)
1999 compose_entry_append(compose, (gchar *)cur->data,
2001 slist_free_strings(cc_list);
2002 g_slist_free(cc_list);
2007 #define SET_ENTRY(entry, str) \
2010 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2013 #define SET_ADDRESS(type, str) \
2016 compose_entry_append(compose, str, type); \
2019 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2021 g_return_if_fail(msginfo != NULL);
2023 SET_ENTRY(subject_entry, msginfo->subject);
2024 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2025 SET_ADDRESS(COMPOSE_CC, compose->cc);
2026 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2027 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2028 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2029 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2031 compose_update_priority_menu_item(compose);
2033 compose_update_gnupg_mode_menu_item(compose);
2035 compose_show_first_last_header(compose, TRUE);
2042 static void compose_insert_sig(Compose *compose, gboolean replace)
2044 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2045 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2051 g_return_if_fail(compose->account != NULL);
2053 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2054 G_CALLBACK(compose_changed_cb),
2057 mark = gtk_text_buffer_get_insert(buffer);
2058 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2059 cur_pos = gtk_text_iter_get_offset (&iter);
2061 gtk_text_buffer_get_end_iter(buffer, &iter);
2063 if (replace && compose->sig_str) {
2065 GtkTextIter first_iter, start_iter, end_iter;
2067 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2069 if (compose->sig_str[0] == '\0')
2072 found = gtk_text_iter_forward_search(&first_iter,
2074 GTK_TEXT_SEARCH_TEXT_ONLY,
2075 &start_iter, &end_iter,
2079 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2084 g_free(compose->sig_str);
2085 compose->sig_str = compose_get_signature_str(compose);
2086 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2087 compose->sig_str = g_strdup("");
2089 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2091 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2092 cur_pos = gtk_text_buffer_get_char_count (buffer);
2094 gtk_text_buffer_get_iter_at_offset (buffer, &iter, cur_pos);
2095 gtk_text_buffer_place_cursor (buffer, &iter);
2097 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2098 G_CALLBACK(compose_changed_cb),
2103 static gchar *compose_get_signature_str(Compose *compose)
2105 gchar *sig_body = NULL;
2106 gchar *sig_str = NULL;
2108 g_return_val_if_fail(compose->account != NULL, NULL);
2110 if (!compose->account->sig_path)
2113 if (compose->account->sig_type == SIG_FILE) {
2114 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2115 g_warning("can't open signature file: %s\n",
2116 compose->account->sig_path);
2121 if (compose->account->sig_type == SIG_COMMAND)
2122 sig_body = get_command_output(compose->account->sig_path);
2126 tmp = file_read_to_str(compose->account->sig_path);
2129 sig_body = normalize_newlines(tmp);
2133 if (compose->account->sig_sep)
2134 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2137 sig_str = g_strconcat("\n\n", sig_body, NULL);
2144 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2147 GtkTextBuffer *buffer;
2150 gchar buf[BUFFSIZE];
2153 gboolean badtxt = FALSE;
2155 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2157 if ((fp = fopen(file, "rb")) == NULL) {
2158 FILE_OP_ERROR(file, "fopen");
2159 return COMPOSE_INSERT_READ_ERROR;
2162 text = GTK_TEXT_VIEW(compose->text);
2163 buffer = gtk_text_view_get_buffer(text);
2164 mark = gtk_text_buffer_get_insert(buffer);
2165 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2167 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2168 G_CALLBACK(text_inserted),
2171 while (fgets(buf, sizeof(buf), fp) != NULL) {
2172 const gchar *cur_encoding = conv_get_current_charset_str();
2174 if (!g_utf8_validate(buf, -1, NULL))
2175 str = conv_codeset_strdup(buf, cur_encoding, CS_UTF_8);
2177 str = g_strdup(buf);
2181 /* strip <CR> if DOS/Windows file,
2182 replace <CR> with <LF> if Macintosh file. */
2185 if (len > 0 && str[len - 1] != '\n') {
2187 if (str[len] == '\r') str[len] = '\n';
2189 gtk_text_buffer_insert(buffer, &iter, str, -1);
2194 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2195 G_CALLBACK(text_inserted),
2201 return COMPOSE_INSERT_INVALID_CHARACTER;
2203 return COMPOSE_INSERT_SUCCESS;
2206 static void compose_attach_append(Compose *compose, const gchar *file,
2207 const gchar *filename,
2208 const gchar *content_type)
2211 gchar *text[N_ATTACH_COLS];
2216 if (!is_file_exist(file)) {
2217 g_warning("File %s doesn't exist\n", file);
2220 if ((size = get_file_size(file)) < 0) {
2221 g_warning("Can't get file size of %s\n", file);
2225 alertpanel_notice(_("File %s is empty."), file);
2228 if ((fp = fopen(file, "rb")) == NULL) {
2229 alertpanel_error(_("Can't read %s."), file);
2234 #if 0 /* NEW COMPOSE GUI */
2235 if (!compose->use_attach) {
2236 GtkItemFactory *ifactory;
2238 ifactory = gtk_item_factory_from_widget(compose->menubar);
2239 menu_set_active(ifactory, "/View/Attachment", TRUE);
2242 ainfo = g_new0(AttachInfo, 1);
2243 ainfo->file = g_strdup(file);
2246 ainfo->content_type = g_strdup(content_type);
2247 if (!strcasecmp(content_type, "message/rfc822")) {
2249 MsgFlags flags = {0, 0};
2252 if (procmime_get_encoding_for_file(file) == ENC_7BIT)
2253 ainfo->encoding = ENC_7BIT;
2255 ainfo->encoding = ENC_8BIT;
2257 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2258 if (msginfo && msginfo->subject)
2259 name = msginfo->subject;
2261 name = g_basename(filename ? filename : file);
2263 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2265 procmsg_msginfo_free(msginfo);
2267 if (!g_strncasecmp(content_type, "text", 4))
2269 procmime_get_encoding_for_file(file);
2271 ainfo->encoding = ENC_BASE64;
2272 ainfo->name = g_strdup
2273 (g_basename(filename ? filename : file));
2276 ainfo->content_type = procmime_get_mime_type(file);
2277 if (!ainfo->content_type) {
2278 ainfo->content_type =
2279 g_strdup("application/octet-stream");
2280 ainfo->encoding = ENC_BASE64;
2281 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
2282 ainfo->encoding = procmime_get_encoding_for_file(file);
2284 ainfo->encoding = ENC_BASE64;
2285 ainfo->name = g_strdup(g_basename(filename ? filename : file));
2289 text[COL_MIMETYPE] = ainfo->content_type;
2290 text[COL_SIZE] = to_human_readable(size);
2291 text[COL_NAME] = ainfo->name;
2293 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2294 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2298 static void compose_use_signing(Compose *compose, gboolean use_signing)
2300 GtkItemFactory *ifactory;
2301 GtkWidget *menuitem = NULL;
2303 compose->use_signing = use_signing;
2304 ifactory = gtk_item_factory_from_widget(compose->menubar);
2305 menuitem = gtk_item_factory_get_item
2306 (ifactory, "/Message/Sign");
2308 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2310 compose_update_gnupg_mode_menu_item(compose);
2313 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2315 GtkItemFactory *ifactory;
2316 GtkWidget *menuitem = NULL;
2318 compose->use_encryption = use_encryption;
2319 ifactory = gtk_item_factory_from_widget(compose->menubar);
2320 menuitem = gtk_item_factory_get_item
2321 (ifactory, "/Message/Encrypt");
2323 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2325 compose_update_gnupg_mode_menu_item(compose);
2327 #endif /* USE_GPGME */
2329 #define NEXT_PART_NOT_CHILD(info) \
2331 node = info->node; \
2332 while (node->children) \
2333 node = g_node_last_child(node); \
2334 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2337 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2341 MimeInfo *firsttext = NULL;
2342 MimeInfo *encrypted = NULL;
2345 const gchar *partname = NULL;
2347 mimeinfo = procmime_scan_message(msginfo);
2348 if (!mimeinfo) return;
2350 if (mimeinfo->node->children == NULL) {
2351 procmime_mimeinfo_free_all(mimeinfo);
2355 /* find first content part */
2356 child = (MimeInfo *) mimeinfo->node->children->data;
2357 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2358 child = (MimeInfo *)child->node->children->data;
2360 if (child->type == MIMETYPE_TEXT) {
2362 debug_print("First text part found\n");
2363 } else if (compose->mode == COMPOSE_REEDIT &&
2364 child->type == MIMETYPE_APPLICATION &&
2365 !strcasecmp(child->subtype, "pgp-encrypted")) {
2367 val = alertpanel(_("Encrypted message"),
2368 _("Cannot re-edit an encrypted message. \n"
2369 "Discard encrypted part?"),
2370 _("Yes"), _("No"), NULL);
2371 if (val == G_ALERTDEFAULT)
2372 encrypted = (MimeInfo *)child->node->parent->data;
2375 child = (MimeInfo *) mimeinfo->node->children->data;
2376 while (child != NULL) {
2377 if (child == encrypted) {
2378 /* skip this part of tree */
2379 NEXT_PART_NOT_CHILD(child);
2383 if (child->type == MIMETYPE_MULTIPART) {
2384 /* get the actual content */
2385 child = procmime_mimeinfo_next(child);
2389 if (child == firsttext) {
2390 child = procmime_mimeinfo_next(child);
2394 if ((compose->mode == COMPOSE_REEDIT ||
2395 compose->mode == COMPOSE_FORWARD_INLINE ||
2396 compose->mode == COMPOSE_FORWARD ) &&
2397 (child->type == MIMETYPE_APPLICATION) &&
2398 !strcmp(child->subtype, "pgp-signature")) {
2400 if (compose->mode == COMPOSE_REEDIT) {
2401 compose->gnupg_mode = GNUPG_MODE_DETACH;
2402 compose_use_signing(compose, TRUE);
2405 child = procmime_mimeinfo_next(child);
2408 outfile = procmime_get_tmp_file_name(child);
2409 if (procmime_get_part(outfile, child) < 0)
2410 g_warning("Can't get the part of multipart message.");
2412 gchar *content_type;
2414 content_type = g_strdup_printf("%s/%s", procmime_get_type_str(child->type), child->subtype);
2415 partname = procmime_mimeinfo_get_parameter(child, "name");
2416 if (partname == NULL)
2418 compose_attach_append(compose, outfile,
2419 partname, content_type);
2420 g_free(content_type);
2423 NEXT_PART_NOT_CHILD(child);
2425 procmime_mimeinfo_free_all(mimeinfo);
2429 #define CHAR_BUF_SIZE 8
2430 #undef NEXT_PART_NOT_CHILD
2432 #define GET_CHAR(iter_p, buf, len) \
2434 GtkTextIter end_iter; \
2436 end_iter = *iter_p; \
2437 gtk_text_iter_forward_char(&end_iter); \
2438 tmp = gtk_text_buffer_get_text(textbuf, iter_p, &end_iter, FALSE); \
2440 glong items_read, items_witten; \
2441 GError *error = NULL; \
2442 gunichar *wide_char; \
2443 strncpy2(buf, tmp, CHAR_BUF_SIZE); \
2444 wide_char = g_utf8_to_ucs4(tmp, -1, \
2445 &items_read, &items_witten, \
2447 if (error != NULL) { \
2448 g_warning("%s\n", error->message); \
2449 g_error_free(error); \
2451 len = wide_char && g_unichar_iswide(*wide_char) ? 2 : 1; \
2452 g_free(wide_char); \
2460 #define DISP_WIDTH(len) \
2461 ((len > 2 && conv_get_current_charset() == C_UTF_8) ? 2 : \
2462 (len == 2 && conv_get_current_charset() == C_UTF_8) ? 1 : len)
2464 #define SPACE_CHARS " \t"
2466 static void compose_wrap_line(Compose *compose)
2468 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2469 GtkTextBuffer *textbuf = gtk_text_view_get_buffer(text);
2471 GtkTextIter insert_iter, iter;
2472 gint ch_len, last_ch_len;
2473 gchar cbuf[CHAR_BUF_SIZE], last_ch;
2475 gint p_start, p_end;
2476 gint line_pos, cur_pos;
2477 gint line_len, cur_len;
2478 gboolean line_end, quoted;
2480 text_len = gtk_text_buffer_get_char_count(textbuf);
2481 mark = gtk_text_buffer_get_insert(textbuf);
2482 gtk_text_buffer_get_iter_at_mark(textbuf, &insert_iter, mark);
2483 cur_pos = gtk_text_iter_get_offset(&insert_iter);
2484 GET_CHAR(&insert_iter, cbuf, ch_len);
2485 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2486 GtkTextIter prev_iter;
2488 return; /* on the paragraph mark */
2489 prev_iter = insert_iter;
2490 gtk_text_iter_backward_char(&prev_iter);
2491 GET_CHAR(&prev_iter, cbuf, ch_len);
2492 if (ch_len == 1 && *cbuf == '\n')
2493 return; /* on the paragraph mark */
2496 /* find paragraph start. */
2497 line_end = quoted = FALSE;
2498 for (iter = insert_iter; gtk_text_iter_backward_char(&iter);) {
2499 GET_CHAR(&iter, cbuf, ch_len);
2500 if (ch_len == 1 && *cbuf == '\n') {
2502 return; /* quoted part */
2504 gtk_text_iter_forward_chars(&iter, 2);
2510 && strchr(prefs_common.quote_chars, *cbuf))
2512 else if (ch_len != 1 || !isspace(*(guchar *)cbuf))
2518 p_start = gtk_text_iter_get_offset(&iter);
2520 /* find paragraph end. */
2522 for (iter = insert_iter; gtk_text_iter_forward_char(&iter);) {
2523 GET_CHAR(&iter, cbuf, ch_len);
2524 if (ch_len == 1 && *cbuf == '\n') {
2527 gtk_text_iter_backward_char(&iter);
2532 if (line_end && ch_len == 1 &&
2533 strchr(prefs_common.quote_chars, *cbuf))
2534 return; /* quoted part */
2539 p_end = gtk_text_iter_get_offset(&iter);
2541 if (p_end >= text_len)
2544 if (p_start >= p_end)
2547 line_len = cur_len = 0;
2551 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2552 gboolean space = FALSE;
2554 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cur_pos);
2556 GET_CHAR(&iter, cbuf, ch_len);
2563 if (ch_len == 1 && isspace(*(guchar *)cbuf))
2566 if (ch_len == 1 && *cbuf == '\n') {
2567 gboolean replace = FALSE;
2568 GtkTextIter next_iter = iter;
2570 gtk_text_iter_forward_char(&next_iter);
2572 if (last_ch_len == 1 && !isspace((guchar)last_ch)) {
2573 if (cur_pos + 1 < p_end) {
2574 GET_CHAR(&next_iter, cbuf, ch_len);
2576 !isspace(*(guchar *)cbuf))
2580 gtk_text_buffer_delete(textbuf, &iter, &next_iter);
2582 gtk_text_buffer_insert(textbuf, &iter, " ", 1);
2588 gtk_text_buffer_get_iter_at_offset
2589 (textbuf, &iter, cur_pos);
2594 last_ch_len = ch_len;
2598 line_pos = cur_pos + 1;
2599 line_len = cur_len + ch_len;
2602 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, line_pos);
2604 if (cur_len + ch_len > prefs_common.linewrap_len &&
2607 GtkTextIter prev_iter = iter;
2609 gtk_text_iter_backward_char(&prev_iter);
2611 GET_CHAR(&prev_iter, cbuf, ch_len);
2612 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2613 gtk_text_buffer_delete(textbuf, &prev_iter, &iter);
2623 gtk_text_buffer_insert(textbuf, &iter, "\n", 1);
2627 cur_len = cur_len - line_len + ch_len;
2633 line_pos = cur_pos + 1;
2634 line_len = cur_len + ch_len;
2642 /* Darko: used when I debug wrapping */
2643 void dump_text(GtkTextBuffer textbuf, int pos, int tlen, int breakoncr)
2646 gchar cbuf[CHAR_BUF_SIZE];
2648 printf("%d [", pos);
2649 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, pos);
2650 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter, pos + tlen);
2651 for (; gtk_text_iter_forward_char(&iter) &&
2652 gtk_text_iter_compare(&iter, &end_iter) < 0;)
2653 GET_CHAR(&iter, cbuf, clen);
2654 if (clen < 0) break;
2655 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2657 fwrite(cbuf, clen, 1, stdout);
2665 WAIT_FOR_INDENT_CHAR,
2666 WAIT_FOR_INDENT_CHAR_OR_SPACE
2669 /* return indent length, we allow:
2670 > followed by spaces/tabs
2671 | followed by spaces/tabs
2672 uppercase characters immediately followed by >,
2673 and the repeating sequences of the above */
2674 /* return indent length */
2675 static guint get_indent_length(GtkTextBuffer *textbuf, guint start_pos, guint text_len)
2678 guint i, ch_len, alnum_cnt = 0;
2679 IndentState state = WAIT_FOR_INDENT_CHAR;
2680 gchar cbuf[CHAR_BUF_SIZE];
2684 if (prefs_common.quote_chars == NULL) {
2688 for (i = start_pos; i < text_len; i++) {
2691 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, i);
2692 GET_CHAR(&iter, cbuf, ch_len);
2696 if (cbuf[0] == '\n')
2699 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2700 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2703 case WAIT_FOR_SPACE:
2704 if (is_space == FALSE)
2706 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2708 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2709 if (is_indent == FALSE && is_space == FALSE &&
2710 !isupper((guchar)cbuf[0]))
2712 if (is_space == TRUE) {
2714 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2715 } else if (is_indent == TRUE) {
2717 state = WAIT_FOR_SPACE;
2720 state = WAIT_FOR_INDENT_CHAR;
2723 case WAIT_FOR_INDENT_CHAR:
2724 if (is_indent == FALSE && !isupper((guchar)cbuf[0]))
2726 if (is_indent == TRUE) {
2728 && !strchr(prefs_common.quote_chars, cbuf[0]))
2731 state = WAIT_FOR_SPACE;
2742 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2748 /* insert quotation string when line was wrapped */
2749 static guint ins_quote(GtkTextBuffer *textbuf, GtkTextIter *iter,
2751 guint prev_line_pos, guint text_len,
2757 GtkTextIter iter1, iter2;
2760 gtk_text_buffer_get_iter_at_offset(textbuf, &iter1,
2762 gtk_text_buffer_get_iter_at_offset(textbuf, &iter2,
2763 prev_line_pos + indent_len);
2764 text = gtk_text_buffer_get_text(textbuf, &iter1, &iter2, FALSE);
2765 if (!text) return 0;
2767 gtk_text_buffer_insert(textbuf, iter, text, -1);
2768 ins_len = g_utf8_strlen(text, -1);
2776 static gboolean is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, guint start_pos)
2780 GtkTextIter end_iter;
2781 if (!compose->account->sig_sep)
2784 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, start_pos+1);
2785 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
2786 start_pos+strlen(compose->account->sig_sep)+1);
2788 if (!strcmp(gtk_text_iter_get_text(&iter, &end_iter),
2789 compose->account->sig_sep)) {
2791 gtk_text_buffer_get_iter_at_offset(textbuf, &iter,
2792 start_pos+strlen(compose->account->sig_sep)+1);
2793 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
2794 start_pos+strlen(compose->account->sig_sep)+2);
2796 if (!strcmp(gtk_text_iter_get_text(&iter, &end_iter),"\n"));
2805 /* check if we should join the next line */
2806 static gboolean join_next_line_is_needed(GtkTextBuffer *textbuf,
2807 guint start_pos, guint tlen,
2808 guint prev_ilen, gboolean autowrap)
2810 guint indent_len, ch_len;
2811 gboolean do_join = FALSE;
2812 gchar cbuf[CHAR_BUF_SIZE];
2814 indent_len = get_indent_length(textbuf, start_pos, tlen);
2816 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2818 gtk_text_buffer_get_iter_at_offset(textbuf, &iter,
2819 start_pos + indent_len);
2820 GET_CHAR(&iter, cbuf, ch_len);
2822 if (ch_len > 0 && (cbuf[0] != '\n'))
2829 static void compose_wrap_line_all(Compose *compose)
2831 compose_wrap_line_all_full(compose, FALSE);
2834 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2836 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2837 GtkTextBuffer *textbuf = gtk_text_view_get_buffer(text);
2838 GtkTextIter iter, end_iter;
2840 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2841 gint line_len = 0, cur_len = 0;
2843 gboolean is_new_line = TRUE, do_delete = FALSE;
2845 gboolean linewrap_quote = TRUE;
2846 gboolean set_editable_pos = FALSE;
2847 gint editable_pos = 0;
2848 guint linewrap_len = prefs_common.linewrap_len;
2849 gchar *qfmt = prefs_common.quotemark;
2850 gchar cbuf[CHAR_BUF_SIZE];
2851 GtkTextMark *cursor_mark = gtk_text_buffer_get_insert(textbuf);
2853 tlen = gtk_text_buffer_get_char_count(textbuf);
2855 for (; cur_pos < tlen; cur_pos++) {
2856 /* mark position of new line - needed for quotation wrap */
2859 i_len = get_indent_length(textbuf, cur_pos, tlen);
2861 is_new_line = FALSE;
2865 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cur_pos);
2866 GET_CHAR(&iter, cbuf, ch_len);
2868 /* fix line length for tabs */
2869 if (ch_len == 1 && *cbuf == '\t') {
2870 guint tab_width = 8;
2871 guint tab_offset = line_len % tab_width;
2873 line_len += tab_width - tab_offset - 1;
2877 /* we have encountered line break */
2878 if (ch_len == 1 && *cbuf == '\n') {
2880 gchar cb[CHAR_BUF_SIZE];
2882 /* should we join the next line */
2883 if ((autowrap || i_len != cur_len) && do_delete &&
2884 !is_sig_separator(compose, textbuf, cur_pos+i_len) &&
2885 join_next_line_is_needed
2886 (textbuf, cur_pos + 1, tlen, i_len, autowrap)) {
2891 /* skip delete if it is continuous URL */
2892 if (do_delete && (line_pos - p_pos <= i_len) &&
2893 gtkut_text_buffer_is_uri_string(textbuf, line_pos,
2897 /* should we delete to perform smart wrapping */
2898 if (line_len < linewrap_len && do_delete) {
2899 /* get rid of newline */
2900 gtk_text_buffer_get_iter_at_offset(textbuf,
2904 gtk_text_iter_forward_char(&end_iter);
2905 gtk_text_buffer_delete(textbuf, &iter, &end_iter);
2908 /* if text starts with quote fmt or with
2909 indent string, delete them */
2912 ilen = gtkut_text_buffer_str_compare_n
2913 (textbuf, cur_pos, p_pos, i_len,
2917 gtk_text_iter_forward_chars
2919 gtk_text_buffer_delete(textbuf,
2926 gtk_text_buffer_get_iter_at_offset(textbuf,
2929 GET_CHAR(&iter, cb, clen);
2931 /* insert space if it's alphanumeric */
2932 if ((cur_pos != line_pos) &&
2933 ((clen > 1) || isalnum((guchar)cb[0]))) {
2934 GtkTextIter cursor_iter;
2935 gboolean go_back = FALSE;
2936 gtk_text_buffer_get_iter_at_mark(textbuf, &cursor_iter, cursor_mark);
2937 if (gtk_text_iter_get_offset(&iter) ==
2938 gtk_text_iter_get_offset(&cursor_iter))
2941 gtk_text_buffer_insert(textbuf, &iter,
2944 gtk_text_buffer_get_iter_at_mark(textbuf, &cursor_iter, cursor_mark);
2945 gtk_text_iter_backward_chars(&cursor_iter, 1);
2946 gtk_text_buffer_place_cursor(textbuf, &cursor_iter);
2951 /* and start over with current line */
2952 cur_pos = p_pos - 1;
2954 line_len = cur_len = 0;
2958 g_print("after delete l_pos=");
2959 dump_text(text, line_pos, tlen, 1);
2961 /* move beginning of line if we are on LF */
2962 gtk_text_buffer_get_iter_at_offset(textbuf,
2965 GET_CHAR(&iter, cb, clen);
2966 if (clen == 1 && *cb == '\n')
2969 g_print("new line_pos=%d\n", line_pos);
2975 /* mark new line beginning */
2976 line_pos = cur_pos + 1;
2977 line_len = cur_len = 0;
2988 /* possible line break */
2989 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2990 line_pos = cur_pos + 1;
2991 line_len = cur_len + ch_len;
2994 /* are we over wrapping length set in preferences ? */
2995 if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
2999 g_print("should wrap cur_pos=%d ", cur_pos);
3000 dump_text(text, p_pos, tlen, 1);
3001 dump_text(text, line_pos, tlen, 1);
3003 /* force wrapping if it is one long word but not URL */
3004 if (line_pos - p_pos <= i_len)
3005 if (!gtkut_text_buffer_is_uri_string
3006 (textbuf, line_pos, tlen))
3007 line_pos = cur_pos - 1;
3009 g_print("new line_pos=%d\n", line_pos);
3012 gtk_text_buffer_get_iter_at_offset(textbuf,
3015 GET_CHAR(&iter, cbuf, clen);
3017 /* if next character is space delete it */
3018 if (clen == 1 && isspace(*(guchar *)cbuf)) {
3019 if (p_pos + i_len != line_pos ||
3020 !gtkut_text_buffer_is_uri_string
3021 (textbuf, line_pos, tlen)) {
3022 /* workaround for correct cursor
3024 if (set_editable_pos == FALSE) {
3025 GtkTextMark *ins = gtk_text_buffer_get_insert(textbuf);
3026 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, ins);
3027 editable_pos = gtk_text_iter_get_offset(&iter);
3028 if (editable_pos == line_pos)
3029 set_editable_pos = TRUE;
3031 gtk_text_buffer_get_iter_at_offset(textbuf,
3034 gtk_text_buffer_get_iter_at_offset(textbuf,
3037 gtk_text_buffer_delete(textbuf, &iter, &end_iter);
3038 //gtk_stext_set_point(text, line_pos);
3039 //gtk_stext_backward_delete(text, 1);
3048 /* if it is URL at beginning of line don't wrap */
3049 if (p_pos + i_len == line_pos &&
3050 gtkut_text_buffer_is_uri_string(textbuf, line_pos, tlen)) {
3052 g_print("found URL at ");
3053 dump_text(text, line_pos, tlen, 1);
3059 gtk_text_buffer_get_iter_at_offset(textbuf,
3062 gtk_text_buffer_insert(textbuf, &iter, "\n", 1);
3063 //gtk_stext_set_point(text, line_pos);
3064 //gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
3065 //gtk_stext_compact_buffer(text);
3068 /* for loop will increase it */
3069 cur_pos = line_pos - 1;
3070 /* start over with current line */
3072 line_len = cur_len = 0;
3073 if (autowrap || i_len > 0) {
3078 g_print("after CR insert ");
3079 dump_text(text, line_pos, tlen, 1);
3080 dump_text(text, cur_pos, tlen, 1);
3083 /* should we insert quotation ? */
3084 if (linewrap_quote && i_len) {
3085 /* only if line is not already quoted */
3086 if (!gtkut_text_buffer_str_compare
3087 (textbuf, line_pos, tlen, qfmt)) {
3090 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, line_pos);
3092 if (line_pos - p_pos > i_len) {
3094 (textbuf, &iter, i_len, p_pos,
3099 g_print("after quote insert ");
3100 dump_text(text, line_pos, tlen, 1);
3108 line_pos = cur_pos + 1;
3109 line_len = cur_len + ch_len;
3111 /* advance to next character in buffer */
3115 if (set_editable_pos && editable_pos <= tlen) {
3116 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, editable_pos);
3117 gtk_text_buffer_place_cursor(textbuf, &iter);
3122 #undef CHAR_BUF_SIZE
3124 static void compose_set_title(Compose *compose)
3129 edited = compose->modified ? _(" [Edited]") : "";
3130 if (compose->account && compose->account->address)
3131 str = g_strdup_printf(_("%s - Compose message%s"),
3132 compose->account->address, edited);
3134 str = g_strdup_printf(_("Compose message%s"), edited);
3135 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3140 * compose_current_mail_account:
3142 * Find a current mail account (the currently selected account, or the
3143 * default account, if a news account is currently selected). If a
3144 * mail account cannot be found, display an error message.
3146 * Return value: Mail account, or NULL if not found.