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);
487 static gboolean compose_headerentry_button_pressed (GtkWidget *entry,
488 GdkEventButton *event,
491 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
493 static void compose_allow_user_actions (Compose *compose, gboolean allow);
496 static void compose_check_all (Compose *compose);
497 static void compose_highlight_all (Compose *compose);
498 static void compose_check_backwards (Compose *compose);
499 static void compose_check_forwards_go (Compose *compose);
502 static gboolean compose_send_control_enter (Compose *compose);
503 static gint compose_defer_auto_save_draft (Compose *compose);
504 static PrefsAccount *compose_guess_forward_account_from_msginfo (MsgInfo *msginfo);
506 static GtkItemFactoryEntry compose_popup_entries[] =
508 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
509 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
510 {N_("/---"), NULL, NULL, 0, "<Separator>"},
511 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
514 static GtkItemFactoryEntry compose_entries[] =
516 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
518 "<control>S", compose_draft_cb, 1, NULL},
519 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
520 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
521 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
522 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
523 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
524 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
526 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
527 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
528 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
529 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
530 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
531 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
532 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
533 {N_("/_Edit/Paste as _quotation"),
534 NULL, compose_paste_as_quote_cb, 0, NULL},
535 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
536 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
537 {N_("/_Edit/A_dvanced/Move a character backward"),
539 compose_advanced_action_cb,
540 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_CHARACTER,
542 {N_("/_Edit/A_dvanced/Move a character forward"),
544 compose_advanced_action_cb,
545 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_CHARACTER,
547 {N_("/_Edit/A_dvanced/Move a word backward"),
549 compose_advanced_action_cb,
550 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BACKWARD_WORD,
552 {N_("/_Edit/A_dvanced/Move a word forward"),
554 compose_advanced_action_cb,
555 COMPOSE_CALL_ADVANCED_ACTION_MOVE_FORWARD_WORD,
557 {N_("/_Edit/A_dvanced/Move to beginning of line"),
558 NULL, /* "<control>A" */
559 compose_advanced_action_cb,
560 COMPOSE_CALL_ADVANCED_ACTION_MOVE_BEGINNING_OF_LINE,
562 {N_("/_Edit/A_dvanced/Move to end of line"),
564 compose_advanced_action_cb,
565 COMPOSE_CALL_ADVANCED_ACTION_MOVE_END_OF_LINE,
567 {N_("/_Edit/A_dvanced/Move to previous line"),
569 compose_advanced_action_cb,
570 COMPOSE_CALL_ADVANCED_ACTION_MOVE_PREVIOUS_LINE,
572 {N_("/_Edit/A_dvanced/Move to next line"),
574 compose_advanced_action_cb,
575 COMPOSE_CALL_ADVANCED_ACTION_MOVE_NEXT_LINE,
577 {N_("/_Edit/A_dvanced/Delete a character backward"),
579 compose_advanced_action_cb,
580 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_CHARACTER,
582 {N_("/_Edit/A_dvanced/Delete a character forward"),
584 compose_advanced_action_cb,
585 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_CHARACTER,
587 {N_("/_Edit/A_dvanced/Delete a word backward"),
588 NULL, /* "<control>W" */
589 compose_advanced_action_cb,
590 COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
592 {N_("/_Edit/A_dvanced/Delete a word forward"),
593 NULL, /* "<alt>D", */
594 compose_advanced_action_cb,
595 COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
597 {N_("/_Edit/A_dvanced/Delete line"),
599 compose_advanced_action_cb,
600 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
602 {N_("/_Edit/A_dvanced/Delete entire line"),
604 compose_advanced_action_cb,
605 COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
607 {N_("/_Edit/A_dvanced/Delete to end of line"),
609 compose_advanced_action_cb,
610 COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END,
612 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
613 {N_("/_Edit/_Wrap current paragraph"),
614 "<control>L", compose_wrap_line, 0, NULL},
615 {N_("/_Edit/Wrap all long _lines"),
616 "<control><alt>L", compose_wrap_line_all, 0, NULL},
617 {N_("/_Edit/Aut_o wrapping"), "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
618 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
619 {N_("/_Edit/Edit with e_xternal editor"),
620 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
622 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
623 {N_("/_Spelling/_Check all or check selection"),
624 NULL, compose_check_all, 0, NULL},
625 {N_("/_Spelling/_Highlight all misspelled words"),
626 NULL, compose_highlight_all, 0, NULL},
627 {N_("/_Spelling/Check _backwards misspelled word"),
628 NULL, compose_check_backwards , 0, NULL},
629 {N_("/_Spelling/_Forward to next misspelled word"),
630 NULL, compose_check_forwards_go, 0, NULL},
631 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
632 {N_("/_Spelling/_Spelling Configuration"),
633 NULL, NULL, 0, "<Branch>"},
635 #if 0 /* NEW COMPOSE GUI */
636 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
637 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
638 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
639 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
640 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
641 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
642 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
643 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
644 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
645 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
646 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
648 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
649 {N_("/_Message/_Send"), "<control>Return",
650 compose_send_cb, 0, NULL},
651 {N_("/_Message/Send _later"), "<shift><control>S",
652 compose_send_later_cb, 0, NULL},
653 #if 0 /* NEW COMPOSE GUI */
654 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
655 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
656 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
657 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
658 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
659 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
660 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
661 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
662 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
665 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
666 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
667 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
668 {N_("/_Message/Mode"), NULL, NULL, 0, "<Branch>"},
669 {N_("/_Message/Mode/MIME"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_DETACH, "<RadioItem>"},
670 {N_("/_Message/Mode/Inline"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_INLINE, "/Message/Mode/MIME"},
671 #endif /* USE_GPGME */
672 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
673 {N_("/_Message/_Priority"), NULL, NULL, 0, "<Branch>"},
674 {N_("/_Message/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
675 {N_("/_Message/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
676 {N_("/_Message/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
677 {N_("/_Message/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
678 {N_("/_Message/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
679 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
680 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
681 {N_("/_Message/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
682 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
683 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
684 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
685 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
686 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
687 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
688 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
691 static GtkTargetEntry compose_mime_types[] =
693 {"text/uri-list", 0, 0}
696 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
697 GPtrArray *attach_files)
699 return compose_generic_new(account, mailto, NULL, attach_files, NULL);
702 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
704 return compose_generic_new(account, NULL, item, NULL, NULL);
707 Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
709 return compose_generic_new( account, NULL, NULL, NULL, listAddress );
712 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
713 GPtrArray *attach_files, GList *listAddress )
716 GtkTextView *textview;
717 GtkTextBuffer *textbuf;
719 GtkItemFactory *ifactory;
721 if (item && item->prefs && item->prefs->enable_default_account)
722 account = account_find_from_id(item->prefs->default_account);
724 if (!account) account = cur_account;
725 g_return_val_if_fail(account != NULL, NULL);
727 compose = compose_create(account, COMPOSE_NEW);
728 ifactory = gtk_item_factory_from_widget(compose->menubar);
730 compose->replyinfo = NULL;
731 compose->fwdinfo = NULL;
733 textview = GTK_TEXT_VIEW(compose->text);
734 textbuf = gtk_text_view_get_buffer(textview);
736 undo_block(compose->undostruct);
738 if (item && item->prefs && item->prefs->enable_default_dictionary &&
740 gtkaspell_change_dict(compose->gtkaspell,
741 item->prefs->default_dictionary);
744 if (account->auto_sig)
745 compose_insert_sig(compose, FALSE);
746 gtk_text_buffer_get_start_iter(textbuf, &iter);
747 gtk_text_buffer_place_cursor(textbuf, &iter);
749 if (account->protocol != A_NNTP) {
750 if (mailto && *mailto != '\0') {
751 compose_entries_set(compose, mailto);
753 } else if (item && item->prefs->enable_default_to) {
754 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
755 compose_entry_mark_default_to(compose, item->prefs->default_to);
757 if (item && item->ret_rcpt) {
758 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
762 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
765 * CLAWS: just don't allow return receipt request, even if the user
766 * may want to send an email. simple but foolproof.
768 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
770 compose_add_field_list( compose, listAddress );
776 for (i = 0; i < attach_files->len; i++) {
777 file = g_ptr_array_index(attach_files, i);
778 compose_attach_append(compose, file, file, NULL);
782 compose_show_first_last_header(compose, TRUE);
784 /* Set save folder */
785 if (item && item->prefs && item->prefs->save_copy_to_folder) {
786 gchar *folderidentifier;
788 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
789 folderidentifier = folder_item_get_identifier(item);
790 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
791 g_free(folderidentifier);
794 gtk_widget_grab_focus(compose->header_last->entry);
796 undo_unblock(compose->undostruct);
798 if (prefs_common.auto_exteditor)
799 compose_exec_ext_editor(compose);
805 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
806 const gchar *followupto, gchar * to)
810 if (!account) account = cur_account;
811 g_return_val_if_fail(account != NULL, NULL);
812 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
814 compose = compose_create(account, COMPOSE_NEW);
816 if (prefs_common.auto_sig)
817 compose_insert_sig(compose);
818 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
819 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
821 compose_entry_append(compose, to, COMPOSE_TO);
822 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
823 gtk_widget_grab_focus(compose->subject_entry);
829 void compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
834 g_return_if_fail(msginfo_list != NULL);
836 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
837 g_return_if_fail(msginfo != NULL);
839 list_len = g_slist_length(msginfo_list);
843 compose_reply(msginfo, prefs_common.reply_with_quote,
844 FALSE, prefs_common.default_reply_list, FALSE, body);
846 case COMPOSE_REPLY_WITH_QUOTE:
847 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, body);
849 case COMPOSE_REPLY_WITHOUT_QUOTE:
850 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
852 case COMPOSE_REPLY_TO_SENDER:
853 compose_reply(msginfo, prefs_common.reply_with_quote,
854 FALSE, FALSE, TRUE, body);
856 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
857 compose_followup_and_reply_to(msginfo,
858 prefs_common.reply_with_quote,
861 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
862 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, body);
864 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
865 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
867 case COMPOSE_REPLY_TO_ALL:
868 compose_reply(msginfo, prefs_common.reply_with_quote,
869 TRUE, FALSE, FALSE, body);
871 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
872 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, body);
874 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
875 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
877 case COMPOSE_REPLY_TO_LIST:
878 compose_reply(msginfo, prefs_common.reply_with_quote,
879 FALSE, TRUE, FALSE, body);
881 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
882 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, body);
884 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
885 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
887 case COMPOSE_FORWARD:
888 if (prefs_common.forward_as_attachment) {
889 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
892 compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
896 case COMPOSE_FORWARD_INLINE:
897 /* check if we reply to more than one Message */
899 compose_forward(NULL, msginfo, FALSE, body, FALSE);
902 /* more messages FALL THROUGH */
903 case COMPOSE_FORWARD_AS_ATTACH:
904 compose_forward_multiple(NULL, msginfo_list);
906 case COMPOSE_REDIRECT:
907 compose_redirect(NULL, msginfo);
910 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
914 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
915 gboolean to_ml, gboolean to_sender,
918 compose_generic_reply(msginfo, quote, to_all, to_ml,
919 to_sender, FALSE, body);
922 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
927 compose_generic_reply(msginfo, quote, to_all, FALSE,
928 to_sender, TRUE, body);
931 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
932 gboolean to_all, gboolean to_ml,
934 gboolean followup_and_reply_to,
937 GtkItemFactory *ifactory;
939 PrefsAccount *account = NULL;
940 PrefsAccount *reply_account;
941 GtkTextView *textview;
942 GtkTextBuffer *textbuf;
946 g_return_if_fail(msginfo != NULL);
947 g_return_if_fail(msginfo->folder != NULL);
949 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
951 g_return_if_fail(account != NULL);
953 if (to_sender && account->protocol == A_NNTP &&
954 !followup_and_reply_to) {
956 account_find_from_address(account->address);
958 reply_account = compose_current_mail_account();
962 reply_account = account;
964 compose = compose_create(account, COMPOSE_REPLY);
965 ifactory = gtk_item_factory_from_widget(compose->menubar);
967 menu_set_active(ifactory, "/Message/Remove references", FALSE);
968 menu_set_sensitive(ifactory, "/Message/Remove references", TRUE);
970 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
971 if (!compose->replyinfo)
972 compose->replyinfo = procmsg_msginfo_copy(msginfo);
974 if (msginfo->folder && msginfo->folder->ret_rcpt)
975 menu_set_active(ifactory, "/Message/Request Return Receipt", TRUE);
977 /* Set save folder */
978 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
979 gchar *folderidentifier;
981 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
982 folderidentifier = folder_item_get_identifier(msginfo->folder);
983 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
984 g_free(folderidentifier);
987 if (compose_parse_header(compose, msginfo) < 0) return;
988 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
989 to_sender, followup_and_reply_to);
990 compose_show_first_last_header(compose, TRUE);
992 textview = (GTK_TEXT_VIEW(compose->text));
993 textbuf = gtk_text_view_get_buffer(textview);
995 undo_block(compose->undostruct);
997 if (msginfo->folder && msginfo->folder->prefs &&
998 msginfo->folder->prefs &&
999 msginfo->folder->prefs->enable_default_dictionary &&
1001 gtkaspell_change_dict(compose->gtkaspell,
1002 msginfo->folder->prefs->default_dictionary);
1008 if (prefs_common.quotemark && *prefs_common.quotemark)
1009 qmark = prefs_common.quotemark;
1013 compose_quote_fmt(compose, compose->replyinfo,
1014 prefs_common.quotefmt,
1018 if (account->auto_sig)
1019 compose_insert_sig(compose, FALSE);
1021 if (quote && prefs_common.linewrap_quote)
1022 compose_wrap_line_all(compose);
1024 cursor_pos = quote_fmt_get_cursor_pos();
1025 gtk_text_buffer_get_start_iter(textbuf, &iter);
1026 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cursor_pos);
1027 gtk_text_buffer_place_cursor(textbuf, &iter);
1029 if (quote && prefs_common.linewrap_quote) {
1030 compose_wrap_line_all(compose);
1031 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), TRUE);
1034 gtk_widget_grab_focus(compose->text);
1036 undo_unblock(compose->undostruct);
1038 if (prefs_common.auto_exteditor)
1039 compose_exec_ext_editor(compose);
1042 #define INSERT_FW_HEADER(var, hdr) \
1043 if (msginfo->var && *msginfo->var) { \
1044 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
1045 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
1046 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
1049 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
1050 gboolean as_attach, const gchar *body,
1051 gboolean no_extedit)
1054 GtkTextView *textview;
1055 GtkTextBuffer *textbuf;
1058 g_return_val_if_fail(msginfo != NULL, NULL);
1059 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1062 !(account = compose_guess_forward_account_from_msginfo
1064 account = cur_account;
1066 compose = compose_create(account, COMPOSE_FORWARD);
1068 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1069 if (!compose->fwdinfo)
1070 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1072 if (msginfo->subject && *msginfo->subject) {
1073 gchar *buf, *buf2, *p;
1075 buf = p = g_strdup(msginfo->subject);
1076 p += subject_get_prefix_length(p);
1077 memmove(buf, p, strlen(p) + 1);
1079 buf2 = g_strdup_printf("Fw: %s", buf);
1080 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1086 textview = GTK_TEXT_VIEW(compose->text);
1087 textbuf = gtk_text_view_get_buffer(textview);
1092 msgfile = procmsg_get_message_file_path(msginfo);
1093 if (!is_file_exist(msgfile))
1094 g_warning("%s: file not exist\n", msgfile);
1096 compose_attach_append(compose, msgfile, msgfile,
1102 MsgInfo *full_msginfo;
1104 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1106 full_msginfo = procmsg_msginfo_copy(msginfo);
1108 if (prefs_common.fw_quotemark &&
1109 *prefs_common.fw_quotemark)
1110 qmark = prefs_common.fw_quotemark;
1114 compose_quote_fmt(compose, full_msginfo,
1115 prefs_common.fw_quotefmt,
1117 compose_attach_parts(compose, msginfo);
1119 procmsg_msginfo_free(full_msginfo);
1122 if (account->auto_sig)
1123 compose_insert_sig(compose, FALSE);
1125 if (prefs_common.linewrap_quote)
1126 compose_wrap_line_all(compose);
1128 gtk_text_buffer_get_start_iter(textbuf, &iter);
1129 gtk_text_buffer_place_cursor(textbuf, &iter);
1131 #if 0 /* NEW COMPOSE GUI */
1132 if (account->protocol != A_NNTP)
1133 gtk_widget_grab_focus(compose->to_entry);
1135 gtk_widget_grab_focus(compose->newsgroups_entry);
1137 gtk_widget_grab_focus(compose->header_last->entry);
1139 if (!no_extedit && prefs_common.auto_exteditor)
1140 compose_exec_ext_editor(compose);
1143 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1144 gchar *folderidentifier;
1146 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1147 folderidentifier = folder_item_get_identifier(msginfo->folder);
1148 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1149 g_free(folderidentifier);
1155 #undef INSERT_FW_HEADER
1157 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1160 GtkTextView *textview;
1161 GtkTextBuffer *textbuf;
1166 g_return_val_if_fail(msginfo_list != NULL, NULL);
1168 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next)
1169 if (((MsgInfo *)msginfo->data)->folder == NULL)
1172 /* guess account from first selected message */
1174 !(account = compose_guess_forward_account_from_msginfo
1175 (msginfo_list->data)))
1176 account = cur_account;
1178 g_return_val_if_fail(account != NULL, NULL);
1180 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1181 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1182 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1185 compose = compose_create(account, COMPOSE_FORWARD);
1187 textview = GTK_TEXT_VIEW(compose->text);
1188 textbuf = gtk_text_view_get_buffer(textview);
1190 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1191 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1192 if (!is_file_exist(msgfile))
1193 g_warning("%s: file not exist\n", msgfile);
1195 compose_attach_append(compose, msgfile, msgfile,
1200 if (account->auto_sig)
1201 compose_insert_sig(compose, FALSE);
1203 if (prefs_common.linewrap_quote)
1204 compose_wrap_line_all(compose);
1206 gtk_text_buffer_get_start_iter(textbuf, &iter);
1207 gtk_text_buffer_place_cursor(textbuf, &iter);
1209 gtk_widget_grab_focus(compose->header_last->entry);
1211 #if 0 /* NEW COMPOSE GUI */
1212 if (account->protocol != A_NNTP)
1213 gtk_widget_grab_focus(compose->to_entry);
1215 gtk_widget_grab_focus(compose->newsgroups_entry);
1221 void compose_reedit(MsgInfo *msginfo)
1224 PrefsAccount *account = NULL;
1225 GtkTextView *textview;
1226 GtkTextBuffer *textbuf;
1230 gchar buf[BUFFSIZE];
1232 gboolean use_signing = FALSE;
1233 gboolean use_encryption = FALSE;
1234 gboolean gnupg_mode = FALSE;
1237 g_return_if_fail(msginfo != NULL);
1238 g_return_if_fail(msginfo->folder != NULL);
1240 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1241 gchar queueheader_buf[BUFFSIZE];
1244 /* Select Account from queue headers */
1245 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1246 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1247 id = atoi(&queueheader_buf[strlen("X-Sylpheed-Account-Id:")]);
1248 account = account_find_from_id(id);
1250 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1251 sizeof(queueheader_buf), "NAID:")) {
1252 id = atoi(&queueheader_buf[strlen("NAID:")]);
1253 account = account_find_from_id(id);
1255 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1256 sizeof(queueheader_buf), "MAID:")) {
1257 id = atoi(&queueheader_buf[strlen("MAID:")]);
1258 account = account_find_from_id(id);
1260 if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1261 sizeof(queueheader_buf), "S:")) {
1262 account = account_find_from_address(queueheader_buf);
1265 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1266 sizeof(queueheader_buf), "X-Sylpheed-Sign:")) {
1267 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Sign:")]);
1268 use_signing = param;
1271 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1272 sizeof(queueheader_buf), "X-Sylpheed-Encrypt:")) {
1273 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Encrypt:")]);
1274 use_encryption = param;
1276 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf,
1277 sizeof(queueheader_buf), "X-Sylpheed-Gnupg-Mode:")) {
1278 param = atoi(&queueheader_buf[strlen("X-Sylpheed-Gnupg-Mode:")]);
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);
1302 compose->gnupg_mode = gnupg_mode;
1303 compose_use_signing(compose, use_signing);
1304 compose_use_encryption(compose, use_encryption);
1306 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1308 if (msginfo->folder->stype == F_QUEUE
1309 || msginfo->folder->stype == F_DRAFT) {
1310 gchar queueheader_buf[BUFFSIZE];
1312 /* Set message save folder */
1313 if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1316 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1317 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1318 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1322 if (compose_parse_header(compose, msginfo) < 0) return;
1323 compose_reedit_set_entry(compose, msginfo);
1325 textview = GTK_TEXT_VIEW(compose->text);
1326 textbuf = gtk_text_view_get_buffer(textview);
1327 mark = gtk_text_buffer_get_insert(textbuf);
1328 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
1330 g_signal_handlers_block_by_func(G_OBJECT(textbuf),
1331 G_CALLBACK(compose_changed_cb),
1334 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1335 g_warning("Can't get text part\n");
1337 while (fgets(buf, sizeof(buf), fp) != NULL) {
1339 gtk_text_buffer_insert(textbuf, &iter, buf, -1);
1344 compose_attach_parts(compose, msginfo);
1346 g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
1347 G_CALLBACK(compose_changed_cb),
1350 gtk_widget_grab_focus(compose->text);
1352 if (prefs_common.auto_exteditor)
1353 compose_exec_ext_editor(compose);
1356 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1360 GtkItemFactory *ifactory;
1363 g_return_val_if_fail(msginfo != NULL, NULL);
1366 account = account_get_reply_account(msginfo,
1367 prefs_common.reply_account_autosel);
1368 g_return_val_if_fail(account != NULL, NULL);
1370 compose = compose_create(account, COMPOSE_REDIRECT);
1371 ifactory = gtk_item_factory_from_widget(compose->menubar);
1373 compose->replyinfo = NULL;
1374 compose->fwdinfo = NULL;
1376 compose_show_first_last_header(compose, TRUE);
1378 gtk_widget_grab_focus(compose->header_last->entry);
1380 filename = procmsg_get_message_file(msginfo);
1381 if (filename == NULL)
1384 compose->redirect_filename = filename;
1386 /* Set save folder */
1387 item = msginfo->folder;
1388 if (item && item->prefs && item->prefs->save_copy_to_folder) {
1389 gchar *folderidentifier;
1391 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
1392 folderidentifier = folder_item_get_identifier(item);
1393 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1394 g_free(folderidentifier);
1397 compose_attach_parts(compose, msginfo);
1399 if (msginfo->subject)
1400 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1402 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1404 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1405 gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), TRUE);
1407 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1408 menu_set_sensitive(ifactory, "/Add...", FALSE);
1409 menu_set_sensitive(ifactory, "/Remove", FALSE);
1410 menu_set_sensitive(ifactory, "/Property...", FALSE);
1412 ifactory = gtk_item_factory_from_widget(compose->menubar);
1413 menu_set_sensitive(ifactory, "/File/Save", FALSE);
1414 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
1415 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
1416 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
1417 menu_set_sensitive(ifactory, "/Edit", FALSE);
1419 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
1420 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
1421 menu_set_sensitive(ifactory, "/Message/Mode/MIME", FALSE);
1422 menu_set_sensitive(ifactory, "/Message/Mode/Inline", FALSE);
1424 menu_set_sensitive(ifactory, "/Message/Priority", FALSE);
1425 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
1426 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1427 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1429 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1430 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1431 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1432 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1433 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1434 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
1435 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
1440 GList *compose_get_compose_list(void)
1442 return compose_list;
1445 void compose_entry_append(Compose *compose, const gchar *address,
1446 ComposeEntryType type)
1450 if (!address || *address == '\0') return;
1452 #if 0 /* NEW COMPOSE GUI */
1455 entry = GTK_ENTRY(compose->cc_entry);
1458 entry = GTK_ENTRY(compose->bcc_entry);
1460 case COMPOSE_NEWSGROUPS:
1461 entry = GTK_ENTRY(compose->newsgroups_entry);
1465 entry = GTK_ENTRY(compose->to_entry);
1469 text = gtk_entry_get_text(entry);
1471 gtk_entry_append_text(entry, ", ");
1472 gtk_entry_append_text(entry, address);
1480 header = N_("Bcc:");
1482 case COMPOSE_REPLYTO:
1483 header = N_("Reply-To:");
1485 case COMPOSE_NEWSGROUPS:
1486 header = N_("Newsgroups:");
1488 case COMPOSE_FOLLOWUPTO:
1489 header = N_( "Followup-To:");
1496 header = prefs_common.trans_hdr ? gettext(header) : header;
1498 compose_add_header_entry(compose, header, (gchar *)address);
1501 void compose_entry_mark_default_to(Compose *compose, const gchar *mailto)
1503 static GtkStyle *bold_style = NULL;
1504 static GdkColor bold_color;
1508 for (h_list = compose->header_list; h_list != NULL; h_list = h_list->next) {
1509 entry = GTK_ENTRY(((ComposeHeaderEntry *)h_list->data)->entry);
1510 if (gtk_entry_get_text(entry) &&
1511 !g_strcasecmp(gtk_entry_get_text(entry), mailto)) {
1512 gtk_widget_ensure_style(GTK_WIDGET(entry));
1514 PangoFontDescription *font_desc = NULL;
1515 gtkut_convert_int_to_gdk_color
1516 (prefs_common.color_new, &bold_color);
1517 bold_style = gtk_style_copy(gtk_widget_get_style
1518 (GTK_WIDGET(entry)));
1520 font_desc = pango_font_description_from_string
1523 if (bold_style->font_desc)
1524 pango_font_description_free
1525 (bold_style->font_desc);
1526 bold_style->font_desc = font_desc;
1528 bold_style->fg[GTK_STATE_NORMAL] = bold_color;
1530 gtk_widget_set_style(GTK_WIDGET(entry), bold_style);
1535 void compose_toolbar_cb(gint action, gpointer data)
1537 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1538 Compose *compose = (Compose*)toolbar_item->parent;
1540 g_return_if_fail(compose != NULL);
1544 compose_send_cb(compose, 0, NULL);
1547 compose_send_later_cb(compose, 0, NULL);
1550 compose_draft_cb(compose, 0, NULL);
1553 compose_insert_file_cb(compose, 0, NULL);
1556 compose_attach_cb(compose, 0, NULL);
1559 compose_insert_sig(compose, FALSE);
1562 compose_ext_editor_cb(compose, 0, NULL);
1564 case A_LINEWRAP_CURRENT:
1565 compose_wrap_line(compose);
1567 case A_LINEWRAP_ALL:
1568 compose_wrap_line_all(compose);
1571 compose_address_cb(compose, 0, NULL);
1574 case A_CHECK_SPELLING:
1575 compose_check_all(compose);
1583 static void compose_entries_set(Compose *compose, const gchar *mailto)
1588 gchar *subject = NULL;
1591 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1594 compose_entry_append(compose, to, COMPOSE_TO);
1596 compose_entry_append(compose, cc, COMPOSE_CC);
1598 compose_entry_append(compose, bcc, COMPOSE_BCC);
1600 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1602 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1603 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1607 mark = gtk_text_buffer_get_insert(buffer);
1608 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1610 gtk_text_buffer_insert(buffer, &iter, body, -1);
1611 gtk_text_buffer_insert(buffer, &iter, "\n", 1);
1621 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1623 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1624 {"Cc:", NULL, TRUE},
1625 {"References:", NULL, FALSE},
1626 {"Bcc:", NULL, TRUE},
1627 {"Newsgroups:", NULL, TRUE},
1628 {"Followup-To:", NULL, TRUE},
1629 {"List-Post:", NULL, FALSE},
1630 {"X-Priority:", NULL, FALSE},
1631 {NULL, NULL, FALSE}};
1647 g_return_val_if_fail(msginfo != NULL, -1);
1649 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1650 procheader_get_header_fields(fp, hentry);
1653 if (hentry[H_REPLY_TO].body != NULL) {
1654 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1655 compose->replyto = hentry[H_REPLY_TO].body;
1656 hentry[H_REPLY_TO].body = NULL;
1658 if (hentry[H_CC].body != NULL) {
1659 conv_unmime_header_overwrite(hentry[H_CC].body);
1660 compose->cc = hentry[H_CC].body;
1661 hentry[H_CC].body = NULL;
1663 if (hentry[H_REFERENCES].body != NULL) {
1664 if (compose->mode == COMPOSE_REEDIT)
1665 compose->references = hentry[H_REFERENCES].body;
1667 compose->references = compose_parse_references
1668 (hentry[H_REFERENCES].body, msginfo->msgid);
1669 g_free(hentry[H_REFERENCES].body);
1671 hentry[H_REFERENCES].body = NULL;
1673 if (hentry[H_BCC].body != NULL) {
1674 if (compose->mode == COMPOSE_REEDIT) {
1675 conv_unmime_header_overwrite(hentry[H_BCC].body);
1676 compose->bcc = hentry[H_BCC].body;
1678 g_free(hentry[H_BCC].body);
1679 hentry[H_BCC].body = NULL;
1681 if (hentry[H_NEWSGROUPS].body != NULL) {
1682 conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
1683 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1684 hentry[H_NEWSGROUPS].body = NULL;
1686 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1687 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1688 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1689 hentry[H_FOLLOWUP_TO].body = NULL;
1691 if (hentry[H_LIST_POST].body != NULL) {
1694 extract_address(hentry[H_LIST_POST].body);
1695 if (hentry[H_LIST_POST].body[0] != '\0') {
1696 scan_mailto_url(hentry[H_LIST_POST].body,
1697 &to, NULL, NULL, NULL, NULL);
1699 g_free(compose->ml_post);
1700 compose->ml_post = to;
1703 g_free(hentry[H_LIST_POST].body);
1704 hentry[H_LIST_POST].body = NULL;
1707 /* CLAWS - X-Priority */
1708 if (compose->mode == COMPOSE_REEDIT)
1709 if (hentry[H_X_PRIORITY].body != NULL) {
1712 priority = atoi(hentry[H_X_PRIORITY].body);
1713 g_free(hentry[H_X_PRIORITY].body);
1715 hentry[H_X_PRIORITY].body = NULL;
1717 if (priority < PRIORITY_HIGHEST ||
1718 priority > PRIORITY_LOWEST)
1719 priority = PRIORITY_NORMAL;
1721 compose->priority = priority;
1724 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1725 compose->inreplyto = g_strdup(msginfo->inreplyto);
1726 else if (compose->mode != COMPOSE_REEDIT &&
1727 msginfo->msgid && *msginfo->msgid) {
1728 compose->inreplyto = g_strdup(msginfo->msgid);
1730 if (!compose->references) {
1731 if (msginfo->inreplyto && *msginfo->inreplyto)
1732 compose->references =
1733 g_strdup_printf("<%s>\n\t<%s>",
1737 compose->references =
1738 g_strconcat("<", msginfo->msgid, ">",
1746 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1748 GSList *ref_id_list, *cur;
1752 ref_id_list = references_list_append(NULL, ref);
1753 if (!ref_id_list) return NULL;
1754 if (msgid && *msgid)
1755 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1760 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1761 /* "<" + Message-ID + ">" + CR+LF+TAB */
1762 len += strlen((gchar *)cur->data) + 5;
1764 if (len > MAX_REFERENCES_LEN) {
1765 /* remove second message-ID */
1766 if (ref_id_list && ref_id_list->next &&
1767 ref_id_list->next->next) {
1768 g_free(ref_id_list->next->data);
1769 ref_id_list = g_slist_remove
1770 (ref_id_list, ref_id_list->next->data);
1772 slist_free_strings(ref_id_list);
1773 g_slist_free(ref_id_list);
1780 new_ref = g_string_new("");
1781 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1782 if (new_ref->len > 0)
1783 g_string_append(new_ref, "\n\t");
1784 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1787 slist_free_strings(ref_id_list);
1788 g_slist_free(ref_id_list);
1790 new_ref_str = new_ref->str;
1791 g_string_free(new_ref, FALSE);
1796 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1797 const gchar *fmt, const gchar *qmark,
1800 static MsgInfo dummyinfo;
1801 gchar *quote_str = NULL;
1805 const gchar *trimmed_body = body;
1808 msginfo = &dummyinfo;
1810 if (qmark != NULL) {
1811 quote_fmt_init(msginfo, NULL, NULL);
1812 quote_fmt_scan_string(qmark);
1815 buf = quote_fmt_get_buffer();
1817 alertpanel_error(_("Quote mark format error."));
1819 Xstrdup_a(quote_str, buf, return NULL)
1822 if (fmt && *fmt != '\0') {
1823 while (trimmed_body && strlen(trimmed_body) > 1
1824 && trimmed_body[0]=='\n')
1827 quote_fmt_init(msginfo, quote_str, trimmed_body);
1828 quote_fmt_scan_string(fmt);
1831 buf = quote_fmt_get_buffer();
1833 alertpanel_error(_("Message reply/forward format error."));
1839 for (p = buf; *p != '\0'; ) {
1840 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
1841 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
1845 g_signal_handlers_block_by_func(G_OBJECT(buffer),
1846 G_CALLBACK(compose_changed_cb),
1848 g_signal_handlers_block_by_func(G_OBJECT(buffer),
1849 G_CALLBACK(text_inserted),
1852 mark = gtk_text_buffer_get_insert(buffer);
1853 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
1855 lastp = strchr(p, '\n');
1856 len = lastp ? lastp - p + 1 : -1;
1858 gtk_text_buffer_insert(buffer, &iter, p, len);
1860 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
1861 G_CALLBACK(compose_changed_cb),
1863 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
1864 G_CALLBACK(text_inserted),
1876 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1877 gboolean to_all, gboolean to_ml,
1879 gboolean followup_and_reply_to)
1881 GSList *cc_list = NULL;
1884 gchar *replyto = NULL;
1885 GHashTable *to_table;
1887 g_return_if_fail(compose->account != NULL);
1888 g_return_if_fail(msginfo != NULL);
1890 if (compose->account->protocol != A_NNTP) {
1891 if (!compose->replyto && to_ml && compose->ml_post
1892 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1893 compose_entry_append(compose,
1896 else if (!(to_all || to_sender)
1898 && msginfo->folder->prefs->enable_default_reply_to) {
1899 compose_entry_append(compose,
1900 msginfo->folder->prefs->default_reply_to,
1903 compose_entry_append(compose,
1904 (compose->replyto && !to_sender)
1905 ? compose->replyto :
1906 msginfo->from ? msginfo->from : "",
1909 if (to_sender || (compose->followup_to &&
1910 !strncmp(compose->followup_to, "poster", 6)))
1911 compose_entry_append
1913 (compose->replyto ? compose->replyto :
1914 msginfo->from ? msginfo->from : ""),
1917 else if (followup_and_reply_to || to_all) {
1918 compose_entry_append
1920 (compose->replyto ? compose->replyto :
1921 msginfo->from ? msginfo->from : ""),
1924 compose_entry_append
1926 compose->followup_to ? compose->followup_to :
1927 compose->newsgroups ? compose->newsgroups : "",
1928 COMPOSE_NEWSGROUPS);
1931 compose_entry_append
1933 compose->followup_to ? compose->followup_to :
1934 compose->newsgroups ? compose->newsgroups : "",
1935 COMPOSE_NEWSGROUPS);
1938 if (msginfo->subject && *msginfo->subject) {
1942 buf = p = g_strdup(msginfo->subject);
1943 p += subject_get_prefix_length(p);
1944 memmove(buf, p, strlen(p) + 1);
1946 buf2 = g_strdup_printf("Re: %s", buf);
1947 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1952 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1954 if (to_ml && compose->ml_post) return;
1955 if (!to_all || compose->account->protocol == A_NNTP) return;
1957 if (compose->replyto) {
1958 Xstrdup_a(replyto, compose->replyto, return);
1959 extract_address(replyto);
1961 if (msginfo->from) {
1962 Xstrdup_a(from, msginfo->from, return);
1963 extract_address(from);
1966 if (replyto && from)
1967 cc_list = address_list_append_with_comments(cc_list, from);
1968 if (to_all && msginfo->folder &&
1969 msginfo->folder->prefs->enable_default_reply_to)
1970 cc_list = address_list_append_with_comments(cc_list,
1971 msginfo->folder->prefs->default_reply_to);
1972 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
1973 cc_list = address_list_append_with_comments(cc_list, compose->cc);
1975 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1977 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
1978 if (compose->account)
1979 g_hash_table_insert(to_table, g_strdup(compose->account->address),
1980 GINT_TO_POINTER(1));
1982 /* remove address on To: and that of current account */
1983 for (cur = cc_list; cur != NULL; ) {
1984 GSList *next = cur->next;
1987 addr = g_strdup(cur->data);
1988 extract_address(addr);
1990 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
1991 cc_list = g_slist_remove(cc_list, cur->data);
1993 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
1997 hash_free_strings(to_table);
1998 g_hash_table_destroy(to_table);
2001 for (cur = cc_list; cur != NULL; cur = cur->next)
2002 compose_entry_append(compose, (gchar *)cur->data,
2004 slist_free_strings(cc_list);
2005 g_slist_free(cc_list);
2010 #define SET_ENTRY(entry, str) \
2013 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
2016 #define SET_ADDRESS(type, str) \
2019 compose_entry_append(compose, str, type); \
2022 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
2024 g_return_if_fail(msginfo != NULL);
2026 SET_ENTRY(subject_entry, msginfo->subject);
2027 SET_ADDRESS(COMPOSE_TO, msginfo->to);
2028 SET_ADDRESS(COMPOSE_CC, compose->cc);
2029 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
2030 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
2031 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
2032 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
2034 compose_update_priority_menu_item(compose);
2036 compose_update_gnupg_mode_menu_item(compose);
2038 compose_show_first_last_header(compose, TRUE);
2045 static void compose_insert_sig(Compose *compose, gboolean replace)
2047 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2048 GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
2054 g_return_if_fail(compose->account != NULL);
2056 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2057 G_CALLBACK(compose_changed_cb),
2060 mark = gtk_text_buffer_get_insert(buffer);
2061 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2062 cur_pos = gtk_text_iter_get_offset (&iter);
2064 gtk_text_buffer_get_end_iter(buffer, &iter);
2066 if (replace && compose->sig_str) {
2068 GtkTextIter first_iter, start_iter, end_iter;
2070 gtk_text_buffer_get_start_iter(buffer, &first_iter);
2072 if (compose->sig_str[0] == '\0')
2075 found = gtk_text_iter_forward_search(&first_iter,
2077 GTK_TEXT_SEARCH_TEXT_ONLY,
2078 &start_iter, &end_iter,
2082 gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
2087 g_free(compose->sig_str);
2088 compose->sig_str = compose_get_signature_str(compose);
2089 if (!compose->sig_str || (replace && !compose->account->auto_sig))
2090 compose->sig_str = g_strdup("");
2092 gtk_text_buffer_insert(buffer, &iter, compose->sig_str, -1);
2094 if (cur_pos > gtk_text_buffer_get_char_count (buffer))
2095 cur_pos = gtk_text_buffer_get_char_count (buffer);
2097 gtk_text_buffer_get_iter_at_offset (buffer, &iter, cur_pos);
2098 gtk_text_buffer_place_cursor (buffer, &iter);
2100 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2101 G_CALLBACK(compose_changed_cb),
2106 static gchar *compose_get_signature_str(Compose *compose)
2108 gchar *sig_body = NULL;
2109 gchar *sig_str = NULL;
2111 g_return_val_if_fail(compose->account != NULL, NULL);
2113 if (!compose->account->sig_path)
2116 if (compose->account->sig_type == SIG_FILE) {
2117 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
2118 g_warning("can't open signature file: %s\n",
2119 compose->account->sig_path);
2124 if (compose->account->sig_type == SIG_COMMAND)
2125 sig_body = get_command_output(compose->account->sig_path);
2129 tmp = file_read_to_str(compose->account->sig_path);
2132 sig_body = normalize_newlines(tmp);
2136 if (compose->account->sig_sep)
2137 sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
2140 sig_str = g_strconcat("\n\n", sig_body, NULL);
2147 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
2150 GtkTextBuffer *buffer;
2153 gchar buf[BUFFSIZE];
2156 gboolean badtxt = FALSE;
2158 g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
2160 if ((fp = fopen(file, "rb")) == NULL) {
2161 FILE_OP_ERROR(file, "fopen");
2162 return COMPOSE_INSERT_READ_ERROR;
2165 text = GTK_TEXT_VIEW(compose->text);
2166 buffer = gtk_text_view_get_buffer(text);
2167 mark = gtk_text_buffer_get_insert(buffer);
2168 gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
2170 g_signal_handlers_block_by_func(G_OBJECT(buffer),
2171 G_CALLBACK(text_inserted),
2174 while (fgets(buf, sizeof(buf), fp) != NULL) {
2175 const gchar *cur_encoding = conv_get_current_charset_str();
2177 if (!g_utf8_validate(buf, -1, NULL))
2178 str = conv_codeset_strdup(buf, cur_encoding, CS_UTF_8);
2180 str = g_strdup(buf);
2184 /* strip <CR> if DOS/Windows file,
2185 replace <CR> with <LF> if Macintosh file. */
2188 if (len > 0 && str[len - 1] != '\n') {
2190 if (str[len] == '\r') str[len] = '\n';
2192 gtk_text_buffer_insert(buffer, &iter, str, -1);
2197 g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
2198 G_CALLBACK(text_inserted),
2204 return COMPOSE_INSERT_INVALID_CHARACTER;
2206 return COMPOSE_INSERT_SUCCESS;
2209 static void compose_attach_append(Compose *compose, const gchar *file,
2210 const gchar *filename,
2211 const gchar *content_type)
2214 gchar *text[N_ATTACH_COLS];
2219 if (!is_file_exist(file)) {
2220 g_warning("File %s doesn't exist\n", file);
2223 if ((size = get_file_size(file)) < 0) {
2224 g_warning("Can't get file size of %s\n", file);
2228 alertpanel_notice(_("File %s is empty."), file);
2231 if ((fp = fopen(file, "rb")) == NULL) {
2232 alertpanel_error(_("Can't read %s."), file);
2237 #if 0 /* NEW COMPOSE GUI */
2238 if (!compose->use_attach) {
2239 GtkItemFactory *ifactory;
2241 ifactory = gtk_item_factory_from_widget(compose->menubar);
2242 menu_set_active(ifactory, "/View/Attachment", TRUE);
2245 ainfo = g_new0(AttachInfo, 1);
2246 ainfo->file = g_strdup(file);
2249 ainfo->content_type = g_strdup(content_type);
2250 if (!strcasecmp(content_type, "message/rfc822")) {
2252 MsgFlags flags = {0, 0};
2255 if (procmime_get_encoding_for_file(file) == ENC_7BIT)
2256 ainfo->encoding = ENC_7BIT;
2258 ainfo->encoding = ENC_8BIT;
2260 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2261 if (msginfo && msginfo->subject)
2262 name = msginfo->subject;
2264 name = g_basename(filename ? filename : file);
2266 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2268 procmsg_msginfo_free(msginfo);
2270 if (!g_strncasecmp(content_type, "text", 4))
2272 procmime_get_encoding_for_file(file);
2274 ainfo->encoding = ENC_BASE64;
2275 ainfo->name = g_strdup
2276 (g_basename(filename ? filename : file));
2279 ainfo->content_type = procmime_get_mime_type(file);
2280 if (!ainfo->content_type) {
2281 ainfo->content_type =
2282 g_strdup("application/octet-stream");
2283 ainfo->encoding = ENC_BASE64;
2284 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
2285 ainfo->encoding = procmime_get_encoding_for_file(file);
2287 ainfo->encoding = ENC_BASE64;
2288 ainfo->name = g_strdup(g_basename(filename ? filename : file));
2292 text[COL_MIMETYPE] = ainfo->content_type;
2293 text[COL_SIZE] = to_human_readable(size);
2294 text[COL_NAME] = ainfo->name;
2296 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2297 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2301 static void compose_use_signing(Compose *compose, gboolean use_signing)
2303 GtkItemFactory *ifactory;
2304 GtkWidget *menuitem = NULL;
2306 compose->use_signing = use_signing;
2307 ifactory = gtk_item_factory_from_widget(compose->menubar);
2308 menuitem = gtk_item_factory_get_item
2309 (ifactory, "/Message/Sign");
2311 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2313 compose_update_gnupg_mode_menu_item(compose);
2316 static void compose_use_encryption(Compose *compose, gboolean use_encryption)
2318 GtkItemFactory *ifactory;
2319 GtkWidget *menuitem = NULL;
2321 compose->use_encryption = use_encryption;
2322 ifactory = gtk_item_factory_from_widget(compose->menubar);
2323 menuitem = gtk_item_factory_get_item
2324 (ifactory, "/Message/Encrypt");
2326 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2328 compose_update_gnupg_mode_menu_item(compose);
2330 #endif /* USE_GPGME */
2332 #define NEXT_PART_NOT_CHILD(info) \
2334 node = info->node; \
2335 while (node->children) \
2336 node = g_node_last_child(node); \
2337 info = procmime_mimeinfo_next((MimeInfo *)node->data); \
2340 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2344 MimeInfo *firsttext = NULL;
2345 MimeInfo *encrypted = NULL;
2348 const gchar *partname = NULL;
2350 mimeinfo = procmime_scan_message(msginfo);
2351 if (!mimeinfo) return;
2353 if (mimeinfo->node->children == NULL) {
2354 procmime_mimeinfo_free_all(mimeinfo);
2358 /* find first content part */
2359 child = (MimeInfo *) mimeinfo->node->children->data;
2360 while (child && child->node->children && (child->type == MIMETYPE_MULTIPART))
2361 child = (MimeInfo *)child->node->children->data;
2363 if (child->type == MIMETYPE_TEXT) {
2365 debug_print("First text part found\n");
2366 } else if (compose->mode == COMPOSE_REEDIT &&
2367 child->type == MIMETYPE_APPLICATION &&
2368 !strcasecmp(child->subtype, "pgp-encrypted")) {
2370 val = alertpanel(_("Encrypted message"),
2371 _("Cannot re-edit an encrypted message. \n"
2372 "Discard encrypted part?"),
2373 _("Yes"), _("No"), NULL);
2374 if (val == G_ALERTDEFAULT)
2375 encrypted = (MimeInfo *)child->node->parent->data;
2378 child = (MimeInfo *) mimeinfo->node->children->data;
2379 while (child != NULL) {
2380 if (child == encrypted) {
2381 /* skip this part of tree */
2382 NEXT_PART_NOT_CHILD(child);
2386 if (child->type == MIMETYPE_MULTIPART) {
2387 /* get the actual content */
2388 child = procmime_mimeinfo_next(child);
2392 if (child == firsttext) {
2393 child = procmime_mimeinfo_next(child);
2397 if ((compose->mode == COMPOSE_REEDIT ||
2398 compose->mode == COMPOSE_FORWARD_INLINE ||
2399 compose->mode == COMPOSE_FORWARD ) &&
2400 (child->type == MIMETYPE_APPLICATION) &&
2401 !strcmp(child->subtype, "pgp-signature")) {
2403 if (compose->mode == COMPOSE_REEDIT) {
2404 compose->gnupg_mode = GNUPG_MODE_DETACH;
2405 compose_use_signing(compose, TRUE);
2408 child = procmime_mimeinfo_next(child);
2411 outfile = procmime_get_tmp_file_name(child);
2412 if (procmime_get_part(outfile, child) < 0)
2413 g_warning("Can't get the part of multipart message.");
2415 gchar *content_type;
2417 content_type = g_strdup_printf("%s/%s", procmime_get_type_str(child->type), child->subtype);
2418 partname = procmime_mimeinfo_get_parameter(child, "name");
2419 if (partname == NULL)
2421 compose_attach_append(compose, outfile,
2422 partname, content_type);
2423 g_free(content_type);
2426 NEXT_PART_NOT_CHILD(child);
2428 procmime_mimeinfo_free_all(mimeinfo);
2432 #define CHAR_BUF_SIZE 8
2433 #undef NEXT_PART_NOT_CHILD
2435 #define GET_CHAR(iter_p, buf, len) \
2437 GtkTextIter end_iter; \
2439 end_iter = *iter_p; \
2440 gtk_text_iter_forward_char(&end_iter); \
2441 tmp = gtk_text_buffer_get_text(textbuf, iter_p, &end_iter, FALSE); \
2443 glong items_read, items_witten; \
2444 GError *error = NULL; \
2445 gunichar *wide_char; \
2446 strncpy2(buf, tmp, CHAR_BUF_SIZE); \
2447 wide_char = g_utf8_to_ucs4(tmp, -1, \
2448 &items_read, &items_witten, \
2450 if (error != NULL) { \
2451 g_warning("%s\n", error->message); \
2452 g_error_free(error); \
2454 len = wide_char && g_unichar_iswide(*wide_char) ? 2 : 1; \
2455 g_free(wide_char); \
2463 #define DISP_WIDTH(len) \
2464 ((len > 2 && conv_get_current_charset() == C_UTF_8) ? 2 : \
2465 (len == 2 && conv_get_current_charset() == C_UTF_8) ? 1 : len)
2467 #define SPACE_CHARS " \t"
2469 static void compose_wrap_line(Compose *compose)
2471 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2472 GtkTextBuffer *textbuf = gtk_text_view_get_buffer(text);
2474 GtkTextIter insert_iter, iter;
2475 gint ch_len, last_ch_len;
2476 gchar cbuf[CHAR_BUF_SIZE], last_ch;
2478 gint p_start, p_end;
2479 gint line_pos, cur_pos;
2480 gint line_len, cur_len;
2481 gboolean line_end, quoted;
2483 text_len = gtk_text_buffer_get_char_count(textbuf);
2484 mark = gtk_text_buffer_get_insert(textbuf);
2485 gtk_text_buffer_get_iter_at_mark(textbuf, &insert_iter, mark);
2486 cur_pos = gtk_text_iter_get_offset(&insert_iter);
2487 GET_CHAR(&insert_iter, cbuf, ch_len);
2488 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2489 GtkTextIter prev_iter;
2491 return; /* on the paragraph mark */
2492 prev_iter = insert_iter;
2493 gtk_text_iter_backward_char(&prev_iter);
2494 GET_CHAR(&prev_iter, cbuf, ch_len);
2495 if (ch_len == 1 && *cbuf == '\n')
2496 return; /* on the paragraph mark */
2499 /* find paragraph start. */
2500 line_end = quoted = FALSE;
2501 for (iter = insert_iter; gtk_text_iter_backward_char(&iter);) {
2502 GET_CHAR(&iter, cbuf, ch_len);
2503 if (ch_len == 1 && *cbuf == '\n') {
2505 return; /* quoted part */
2507 gtk_text_iter_forward_chars(&iter, 2);
2513 && strchr(prefs_common.quote_chars, *cbuf))
2515 else if (ch_len != 1 || !isspace(*(guchar *)cbuf))
2521 p_start = gtk_text_iter_get_offset(&iter);
2523 /* find paragraph end. */
2525 for (iter = insert_iter; gtk_text_iter_forward_char(&iter);) {
2526 GET_CHAR(&iter, cbuf, ch_len);
2527 if (ch_len == 1 && *cbuf == '\n') {
2530 gtk_text_iter_backward_char(&iter);
2535 if (line_end && ch_len == 1 &&
2536 strchr(prefs_common.quote_chars, *cbuf))
2537 return; /* quoted part */
2542 p_end = gtk_text_iter_get_offset(&iter);
2544 if (p_end >= text_len)
2547 if (p_start >= p_end)
2550 line_len = cur_len = 0;
2554 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2555 gboolean space = FALSE;
2557 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cur_pos);
2559 GET_CHAR(&iter, cbuf, ch_len);
2566 if (ch_len == 1 && isspace(*(guchar *)cbuf))
2569 if (ch_len == 1 && *cbuf == '\n') {
2570 gboolean replace = FALSE;
2571 GtkTextIter next_iter = iter;
2573 gtk_text_iter_forward_char(&next_iter);
2575 if (last_ch_len == 1 && !isspace((guchar)last_ch)) {
2576 if (cur_pos + 1 < p_end) {
2577 GET_CHAR(&next_iter, cbuf, ch_len);
2579 !isspace(*(guchar *)cbuf))
2583 gtk_text_buffer_delete(textbuf, &iter, &next_iter);
2585 gtk_text_buffer_insert(textbuf, &iter, " ", 1);
2591 gtk_text_buffer_get_iter_at_offset
2592 (textbuf, &iter, cur_pos);
2597 last_ch_len = ch_len;
2601 line_pos = cur_pos + 1;
2602 line_len = cur_len + ch_len;
2605 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, line_pos);
2607 if (cur_len + ch_len > prefs_common.linewrap_len &&
2610 GtkTextIter prev_iter = iter;
2612 gtk_text_iter_backward_char(&prev_iter);
2614 GET_CHAR(&prev_iter, cbuf, ch_len);
2615 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2616 gtk_text_buffer_delete(textbuf, &prev_iter, &iter);
2626 gtk_text_buffer_insert(textbuf, &iter, "\n", 1);
2630 cur_len = cur_len - line_len + ch_len;
2636 line_pos = cur_pos + 1;
2637 line_len = cur_len + ch_len;
2645 /* Darko: used when I debug wrapping */
2646 void dump_text(GtkTextBuffer textbuf, int pos, int tlen, int breakoncr)
2649 gchar cbuf[CHAR_BUF_SIZE];
2651 printf("%d [", pos);
2652 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, pos);
2653 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter, pos + tlen);
2654 for (; gtk_text_iter_forward_char(&iter) &&
2655 gtk_text_iter_compare(&iter, &end_iter) < 0;)
2656 GET_CHAR(&iter, cbuf, clen);
2657 if (clen < 0) break;
2658 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2660 fwrite(cbuf, clen, 1, stdout);
2668 WAIT_FOR_INDENT_CHAR,
2669 WAIT_FOR_INDENT_CHAR_OR_SPACE
2672 /* return indent length, we allow:
2673 > followed by spaces/tabs
2674 | followed by spaces/tabs
2675 uppercase characters immediately followed by >,
2676 and the repeating sequences of the above */
2677 /* return indent length */
2678 static guint get_indent_length(GtkTextBuffer *textbuf, guint start_pos, guint text_len)
2681 guint i, ch_len, alnum_cnt = 0;
2682 IndentState state = WAIT_FOR_INDENT_CHAR;
2683 gchar cbuf[CHAR_BUF_SIZE];
2687 if (prefs_common.quote_chars == NULL) {
2691 for (i = start_pos; i < text_len; i++) {
2694 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, i);
2695 GET_CHAR(&iter, cbuf, ch_len);
2699 if (cbuf[0] == '\n')
2702 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2703 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2706 case WAIT_FOR_SPACE:
2707 if (is_space == FALSE)
2709 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2711 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2712 if (is_indent == FALSE && is_space == FALSE &&
2713 !isupper((guchar)cbuf[0]))
2715 if (is_space == TRUE) {
2717 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2718 } else if (is_indent == TRUE) {
2720 state = WAIT_FOR_SPACE;
2723 state = WAIT_FOR_INDENT_CHAR;
2726 case WAIT_FOR_INDENT_CHAR:
2727 if (is_indent == FALSE && !isupper((guchar)cbuf[0]))
2729 if (is_indent == TRUE) {
2731 && !strchr(prefs_common.quote_chars, cbuf[0]))
2734 state = WAIT_FOR_SPACE;
2745 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2751 /* insert quotation string when line was wrapped */
2752 static guint ins_quote(GtkTextBuffer *textbuf, GtkTextIter *iter,
2754 guint prev_line_pos, guint text_len,
2760 GtkTextIter iter1, iter2;
2763 gtk_text_buffer_get_iter_at_offset(textbuf, &iter1,
2765 gtk_text_buffer_get_iter_at_offset(textbuf, &iter2,
2766 prev_line_pos + indent_len);
2767 text = gtk_text_buffer_get_text(textbuf, &iter1, &iter2, FALSE);
2768 if (!text) return 0;
2770 gtk_text_buffer_insert(textbuf, iter, text, -1);
2771 ins_len = g_utf8_strlen(text, -1);
2779 static gboolean is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, guint start_pos)
2783 GtkTextIter end_iter;
2784 if (!compose->account->sig_sep)
2787 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, start_pos+1);
2788 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
2789 start_pos+strlen(compose->account->sig_sep)+1);
2791 if (!strcmp(gtk_text_iter_get_text(&iter, &end_iter),
2792 compose->account->sig_sep)) {
2794 gtk_text_buffer_get_iter_at_offset(textbuf, &iter,
2795 start_pos+strlen(compose->account->sig_sep)+1);
2796 gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
2797 start_pos+strlen(compose->account->sig_sep)+2);
2799 if (!strcmp(gtk_text_iter_get_text(&iter, &end_iter),"\n"));
2808 /* check if we should join the next line */
2809 static gboolean join_next_line_is_needed(GtkTextBuffer *textbuf,
2810 guint start_pos, guint tlen,
2811 guint prev_ilen, gboolean autowrap)
2813 guint indent_len, ch_len;
2814 gboolean do_join = FALSE;
2815 gchar cbuf[CHAR_BUF_SIZE];
2817 indent_len = get_indent_length(textbuf, start_pos, tlen);
2819 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2821 gtk_text_buffer_get_iter_at_offset(textbuf, &iter,
2822 start_pos + indent_len);
2823 GET_CHAR(&iter, cbuf, ch_len);
2825 if (ch_len > 0 && (cbuf[0] != '\n'))
2832 static void compose_wrap_line_all(Compose *compose)
2834 compose_wrap_line_all_full(compose, FALSE);
2837 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2839 GtkTextView *text = GTK_TEXT_VIEW(compose->text);
2840 GtkTextBuffer *textbuf = gtk_text_view_get_buffer(text);
2841 GtkTextIter iter, end_iter;
2843 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2844 gint line_len = 0, cur_len = 0;
2846 gboolean is_new_line = TRUE, do_delete = FALSE;
2848 gboolean linewrap_quote = TRUE;
2849 gboolean set_editable_pos = FALSE;
2850 gint editable_pos = 0;
2851 guint linewrap_len = prefs_common.linewrap_len;
2852 gchar *qfmt = prefs_common.quotemark;
2853 gchar cbuf[CHAR_BUF_SIZE];
2854 GtkTextMark *cursor_mark = gtk_text_buffer_get_insert(textbuf);
2856 tlen = gtk_text_buffer_get_char_count(textbuf);
2858 for (; cur_pos < tlen; cur_pos++) {
2859 /* mark position of new line - needed for quotation wrap */
2862 i_len = get_indent_length(textbuf, cur_pos, tlen);
2864 is_new_line = FALSE;
2868 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cur_pos);
2869 GET_CHAR(&iter, cbuf, ch_len);
2871 /* fix line length for tabs */
2872 if (ch_len == 1 && *cbuf == '\t') {
2873 guint tab_width = 8;
2874 guint tab_offset = line_len % tab_width;
2876 line_len += tab_width - tab_offset - 1;
2880 /* we have encountered line break */
2881 if (ch_len == 1 && *cbuf == '\n') {
2883 gchar cb[CHAR_BUF_SIZE];
2885 /* should we join the next line */
2886 if ((autowrap || i_len != cur_len) && do_delete &&
2887 !is_sig_separator(compose, textbuf, cur_pos+i_len) &&
2888 join_next_line_is_needed
2889 (textbuf, cur_pos + 1, tlen, i_len, autowrap)) {
2894 /* skip delete if it is continuous URL */
2895 if (do_delete && (line_pos - p_pos <= i_len) &&
2896 gtkut_text_buffer_is_uri_string(textbuf, line_pos,
2900 /* should we delete to perform smart wrapping */
2901 if (line_len < linewrap_len && do_delete) {
2902 /* get rid of newline */
2903 gtk_text_buffer_get_iter_at_offset(textbuf,
2907 gtk_text_iter_forward_char(&end_iter);
2908 gtk_text_buffer_delete(textbuf, &iter, &end_iter);
2911 /* if text starts with quote fmt or with
2912 indent string, delete them */
2915 ilen = gtkut_text_buffer_str_compare_n
2916 (textbuf, cur_pos, p_pos, i_len,
2920 gtk_text_iter_forward_chars
2922 gtk_text_buffer_delete(textbuf,
2929 gtk_text_buffer_get_iter_at_offset(textbuf,
2932 GET_CHAR(&iter, cb, clen);
2934 /* insert space if it's alphanumeric */
2935 if ((cur_pos != line_pos) &&
2936 ((clen > 1) || isalnum((guchar)cb[0]))) {
2937 GtkTextIter cursor_iter;
2938 gboolean go_back = FALSE;
2939 gtk_text_buffer_get_iter_at_mark(textbuf, &cursor_iter, cursor_mark);
2940 if (gtk_text_iter_get_offset(&iter) ==
2941 gtk_text_iter_get_offset(&cursor_iter))
2944 gtk_text_buffer_insert(textbuf, &iter,
2947 gtk_text_buffer_get_iter_at_mark(textbuf, &cursor_iter, cursor_mark);
2948 gtk_text_iter_backward_chars(&cursor_iter, 1);
2949 gtk_text_buffer_place_cursor(textbuf, &cursor_iter);
2954 /* and start over with current line */
2955 cur_pos = p_pos - 1;
2957 line_len = cur_len = 0;
2961 g_print("after delete l_pos=");
2962 dump_text(text, line_pos, tlen, 1);
2964 /* move beginning of line if we are on LF */
2965 gtk_text_buffer_get_iter_at_offset(textbuf,
2968 GET_CHAR(&iter, cb, clen);
2969 if (clen == 1 && *cb == '\n')
2972 g_print("new line_pos=%d\n", line_pos);
2978 /* mark new line beginning */
2979 line_pos = cur_pos + 1;
2980 line_len = cur_len = 0;
2991 /* possible line break */
2992 if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
2993 line_pos = cur_pos + 1;
2994 line_len = cur_len + ch_len;
2997 /* are we over wrapping length set in preferences ? */
2998 if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
3002 g_print("should wrap cur_pos=%d ", cur_pos);
3003 dump_text(text, p_pos, tlen, 1);
3004 dump_text(text, line_pos, tlen, 1);
3006 /* force wrapping if it is one long word but not URL */
3007 if (line_pos - p_pos <= i_len)
3008 if (!gtkut_text_buffer_is_uri_string
3009 (textbuf, line_pos, tlen))
3010 line_pos = cur_pos - 1;
3012 g_print("new line_pos=%d\n", line_pos);
3015 gtk_text_buffer_get_iter_at_offset(textbuf,
3018 GET_CHAR(&iter, cbuf, clen);
3020 /* if next character is space delete it */
3021 if (clen == 1 && isspace(*(guchar *)cbuf)) {
3022 if (p_pos + i_len != line_pos ||
3023 !gtkut_text_buffer_is_uri_string
3024 (textbuf, line_pos, tlen)) {
3025 /* workaround for correct cursor
3027 if (set_editable_pos == FALSE) {
3028 GtkTextMark *ins = gtk_text_buffer_get_insert(textbuf);
3029 gtk_text_buffer_get_iter_at_mark(textbuf, &iter, ins);
3030 editable_pos = gtk_text_iter_get_offset(&iter);
3031 if (editable_pos == line_pos)
3032 set_editable_pos = TRUE;
3034 gtk_text_buffer_get_iter_at_offset(textbuf,
3037 gtk_text_buffer_get_iter_at_offset(textbuf,
3040 gtk_text_buffer_delete(textbuf, &iter, &end_iter);
3041 //gtk_stext_set_point(text, line_pos);
3042 //gtk_stext_backward_delete(text, 1);
3051 /* if it is URL at beginning of line don't wrap */
3052 if (p_pos + i_len == line_pos &&
3053 gtkut_text_buffer_is_uri_string(textbuf, line_pos, tlen)) {
3055 g_print("found URL at ");
3056 dump_text(text, line_pos, tlen, 1);
3062 gtk_text_buffer_get_iter_at_offset(textbuf,
3065 gtk_text_buffer_insert(textbuf, &iter, "\n", 1);
3066 //gtk_stext_set_point(text, line_pos);
3067 //gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
3068 //gtk_stext_compact_buffer(text);
3071 /* for loop will increase it */
3072 cur_pos = line_pos - 1;
3073 /* start over with current line */
3075 line_len = cur_len = 0;
3076 if (autowrap || i_len > 0) {
3081 g_print("after CR insert ");
3082 dump_text(text, line_pos, tlen, 1);
3083 dump_text(text, cur_pos, tlen, 1);
3086 /* should we insert quotation ? */
3087 if (linewrap_quote && i_len) {
3088 /* only if line is not already quoted */
3089 if (!gtkut_text_buffer_str_compare
3090 (textbuf, line_pos, tlen, qfmt)) {
3093 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, line_pos);
3095 if (line_pos - p_pos > i_len) {
3097 (textbuf, &iter, i_len, p_pos,
3102 g_print("after quote insert ");
3103 dump_text(text, line_pos, tlen, 1);
3111 line_pos = cur_pos + 1;
3112 line_len = cur_len + ch_len;
3114 /* advance to next character in buffer */
3118 if (set_editable_pos && editable_pos <= tlen) {
3119 gtk_text_buffer_get_iter_at_offset(textbuf, &iter, editable_pos);
3120 gtk_text_buffer_place_cursor(textbuf, &iter);
3125 #undef CHAR_BUF_SIZE
3127 static void compose_set_title(Compose *compose)
3132 edited = compose->modified ? _(" [Edited]") : "";
3133 if (compose->account && compose->account->address)
3134 str = g_strdup_printf(_("%s - Compose message%s"),
3135 compose->account->address, edited);
3137 str = g_strdup_printf(_("Compose message%s"), edited);
3138 gtk_window_set_title(GTK_WINDOW(compose->window), str);
3143 * compose_current_mail_account:
3145 * Find a current mail account (the currently selected account, or the