2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2003 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/gtkthemes.h>
51 #include <gtk/gtkdnd.h>
56 #include <sys/types.h>
60 /* #include <sys/utsname.h> */
66 #if (HAVE_WCTYPE_H && HAVE_WCHAR_H)
73 #include "mainwindow.h"
76 #include "addressbook.h"
77 #include "folderview.h"
80 #include "stock_pixmap.h"
81 #include "send_message.h"
84 #include "customheader.h"
85 #include "prefs_common.h"
86 #include "prefs_account.h"
90 #include "procheader.h"
92 #include "statusbar.h"
95 #include "quoted-printable.h"
100 #include "alertpanel.h"
101 #include "manage_window.h"
102 #include "gtkshruler.h"
104 #include "addr_compl.h"
105 #include "quote_fmt.h"
106 #include "template.h"
108 #include "foldersel.h"
112 # include "rfc2015.h"
122 #define N_ATTACH_COLS 3
126 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
127 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
128 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
129 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
130 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
131 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
132 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
133 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
134 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
135 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
136 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
137 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
138 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
139 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
140 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END
141 } ComposeCallGtkSTextAction;
145 PRIORITY_HIGHEST = 1,
152 #define B64_LINE_SIZE 57
153 #define B64_BUFFSIZE 77
155 #define MAX_REFERENCES_LEN 999
157 static GdkColor quote_color = {0, 0, 0, 0xbfff};
159 static GList *compose_list = NULL;
161 Compose *compose_generic_new (PrefsAccount *account,
164 GPtrArray *attach_files);
166 static Compose *compose_create (PrefsAccount *account,
169 static GtkWidget *compose_account_option_menu_create
171 static void compose_set_template_menu (Compose *compose);
172 static void compose_template_apply (Compose *compose,
175 static void compose_destroy (Compose *compose);
177 static void compose_entries_set (Compose *compose,
178 const gchar *mailto);
179 static gint compose_parse_header (Compose *compose,
181 static gchar *compose_parse_references (const gchar *ref,
184 static gchar *compose_quote_fmt (Compose *compose,
190 static void compose_reply_set_entry (Compose *compose,
196 followup_and_reply_to);
197 static void compose_reedit_set_entry (Compose *compose,
199 static void compose_insert_sig (Compose *compose,
201 static gchar *compose_get_signature_str (Compose *compose);
202 static void compose_insert_file (Compose *compose,
204 static void compose_attach_append (Compose *compose,
207 const gchar *content_type);
208 static void compose_attach_parts (Compose *compose,
210 static void compose_wrap_line (Compose *compose);
211 static void compose_wrap_line_all (Compose *compose);
212 static void compose_wrap_line_all_full (Compose *compose,
214 static void compose_set_title (Compose *compose);
215 static void compose_select_account (Compose *compose,
216 PrefsAccount *account,
219 static PrefsAccount *compose_current_mail_account(void);
220 /* static gint compose_send (Compose *compose); */
221 static gboolean compose_check_for_valid_recipient
223 static gboolean compose_check_entries (Compose *compose,
224 gboolean check_subject);
225 static gint compose_write_to_file (Compose *compose,
228 static gint compose_write_body_to_file (Compose *compose,
230 static gint compose_remove_reedit_target (Compose *compose);
231 void compose_remove_draft (Compose *compose);
232 static gint compose_queue (Compose *compose,
235 static gint compose_queue_sub (Compose *compose,
238 gboolean check_subject);
239 static void compose_write_attach (Compose *compose,
241 static gint compose_write_headers (Compose *compose,
243 const gchar *charset,
244 EncodingType encoding,
247 static void compose_convert_header (gchar *dest,
251 gboolean addr_field);
252 static void compose_generate_msgid (Compose *compose,
256 static void compose_attach_info_free (AttachInfo *ainfo);
257 static void compose_attach_remove_selected (Compose *compose);
259 static void compose_attach_property (Compose *compose);
260 static void compose_attach_property_create (gboolean *cancelled);
261 static void attach_property_ok (GtkWidget *widget,
262 gboolean *cancelled);
263 static void attach_property_cancel (GtkWidget *widget,
264 gboolean *cancelled);
265 static gint attach_property_delete_event (GtkWidget *widget,
267 gboolean *cancelled);
268 static void attach_property_key_pressed (GtkWidget *widget,
270 gboolean *cancelled);
272 static void compose_exec_ext_editor (Compose *compose);
273 static gint compose_exec_ext_editor_real (const gchar *file);
274 static gboolean compose_ext_editor_kill (Compose *compose);
275 static void compose_input_cb (gpointer data,
277 GdkInputCondition condition);
278 static void compose_set_ext_editor_sensitive (Compose *compose,
281 static void compose_undo_state_changed (UndoMain *undostruct,
286 static gint calc_cursor_xpos (GtkSText *text,
290 static void compose_create_header_entry (Compose *compose);
291 static void compose_add_header_entry (Compose *compose, gchar *header, gchar *text);
292 static void compose_update_priority_menu_item(Compose * compose);
294 /* callback functions */
296 static gboolean compose_edit_size_alloc (GtkEditable *widget,
297 GtkAllocation *allocation,
298 GtkSHRuler *shruler);
299 static void account_activated (GtkMenuItem *menuitem,
301 static void attach_selected (GtkCList *clist,
306 static void attach_button_pressed (GtkWidget *widget,
307 GdkEventButton *event,
309 static void attach_key_pressed (GtkWidget *widget,
313 static void compose_send_cb (gpointer data,
316 static void compose_send_later_cb (gpointer data,
320 static void compose_draft_cb (gpointer data,
324 static void compose_attach_cb (gpointer data,
327 static void compose_insert_file_cb (gpointer data,
330 static void compose_insert_sig_cb (gpointer data,
334 static void compose_close_cb (gpointer data,
338 static void compose_address_cb (gpointer data,
341 static void compose_template_activate_cb(GtkWidget *widget,
344 static void compose_ext_editor_cb (gpointer data,
348 static gint compose_delete_cb (GtkWidget *widget,
351 static void compose_destroy_cb (GtkWidget *widget,
354 static void compose_undo_cb (Compose *compose);
355 static void compose_redo_cb (Compose *compose);
356 static void compose_cut_cb (Compose *compose);
357 static void compose_copy_cb (Compose *compose);
358 static void compose_paste_cb (Compose *compose);
359 static void compose_paste_as_quote_cb (Compose *compose);
360 static void compose_allsel_cb (Compose *compose);
362 static void compose_gtk_stext_action_cb (Compose *compose,
363 ComposeCallGtkSTextAction action);
365 static void compose_grab_focus_cb (GtkWidget *widget,
368 static void compose_changed_cb (GtkEditable *editable,
370 static void compose_button_press_cb (GtkWidget *widget,
371 GdkEventButton *event,
374 static void compose_key_press_cb (GtkWidget *widget,
380 static void compose_toggle_to_cb (gpointer data,
383 static void compose_toggle_cc_cb (gpointer data,
386 static void compose_toggle_bcc_cb (gpointer data,
389 static void compose_toggle_replyto_cb (gpointer data,
392 static void compose_toggle_followupto_cb(gpointer data,
395 static void compose_toggle_attach_cb (gpointer data,
399 static void compose_toggle_ruler_cb (gpointer data,
403 static void compose_toggle_sign_cb (gpointer data,
406 static void compose_toggle_encrypt_cb (gpointer data,
409 static void compose_set_gnupg_mode_cb (gpointer data,
412 static void compose_update_gnupg_mode_menu_item(Compose * compose);
413 static void activate_gnupg_mode (Compose *compose,
414 PrefsAccount *account);
416 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
418 static void compose_toggle_remove_refs_cb(gpointer data, guint action,
420 static void compose_set_priority_cb (gpointer data,
424 static void compose_attach_drag_received_cb (GtkWidget *widget,
425 GdkDragContext *drag_context,
428 GtkSelectionData *data,
432 static void compose_insert_drag_received_cb (GtkWidget *widget,
433 GdkDragContext *drag_context,
436 GtkSelectionData *data,
442 static void to_activated (GtkWidget *widget,
444 static void newsgroups_activated (GtkWidget *widget,
446 static void cc_activated (GtkWidget *widget,
448 static void bcc_activated (GtkWidget *widget,
450 static void replyto_activated (GtkWidget *widget,
452 static void followupto_activated (GtkWidget *widget,
454 static void subject_activated (GtkWidget *widget,
458 static void text_activated (GtkWidget *widget,
460 static void text_inserted (GtkWidget *widget,
465 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
466 gboolean to_all, gboolean to_ml,
468 gboolean followup_and_reply_to,
471 void compose_headerentry_changed_cb (GtkWidget *entry,
472 ComposeHeaderEntry *headerentry);
473 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
475 ComposeHeaderEntry *headerentry);
477 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
480 static void compose_check_all (Compose *compose);
481 static void compose_highlight_all (Compose *compose);
482 static void compose_check_backwards (Compose *compose);
483 static void compose_check_forwards_go (Compose *compose);
486 static gboolean compose_send_control_enter (Compose *compose);
488 static GtkItemFactoryEntry compose_popup_entries[] =
490 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
491 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
492 {N_("/---"), NULL, NULL, 0, "<Separator>"},
493 {N_("/_Properties..."), NULL, compose_attach_property, 0, NULL}
496 static GtkItemFactoryEntry compose_entries[] =
498 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
499 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
500 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
501 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig_cb, 0, NULL},
502 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
503 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
505 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
506 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
507 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
508 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
509 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
510 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
511 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
512 {N_("/_Edit/Paste as _quotation"),
513 NULL, compose_paste_as_quote_cb, 0, NULL},
514 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
515 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
516 {N_("/_Edit/A_dvanced/Move a character backward"),
518 compose_gtk_stext_action_cb,
519 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
521 {N_("/_Edit/A_dvanced/Move a character forward"),
523 compose_gtk_stext_action_cb,
524 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
526 {N_("/_Edit/A_dvanced/Move a word backward"),
528 compose_gtk_stext_action_cb,
529 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
531 {N_("/_Edit/A_dvanced/Move a word forward"),
533 compose_gtk_stext_action_cb,
534 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
536 {N_("/_Edit/A_dvanced/Move to beginning of line"),
537 NULL, /* "<control>A" */
538 compose_gtk_stext_action_cb,
539 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
541 {N_("/_Edit/A_dvanced/Move to end of line"),
543 compose_gtk_stext_action_cb,
544 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
546 {N_("/_Edit/A_dvanced/Move to previous line"),
548 compose_gtk_stext_action_cb,
549 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
551 {N_("/_Edit/A_dvanced/Move to next line"),
553 compose_gtk_stext_action_cb,
554 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
556 {N_("/_Edit/A_dvanced/Delete a character backward"),
558 compose_gtk_stext_action_cb,
559 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
561 {N_("/_Edit/A_dvanced/Delete a character forward"),
563 compose_gtk_stext_action_cb,
564 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
566 {N_("/_Edit/A_dvanced/Delete a word backward"),
567 NULL, /* "<control>W" */
568 compose_gtk_stext_action_cb,
569 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
571 {N_("/_Edit/A_dvanced/Delete a word forward"),
572 NULL, /* "<alt>D", */
573 compose_gtk_stext_action_cb,
574 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
576 {N_("/_Edit/A_dvanced/Delete line"),
578 compose_gtk_stext_action_cb,
579 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
581 {N_("/_Edit/A_dvanced/Delete entire line"),
583 compose_gtk_stext_action_cb,
584 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
586 {N_("/_Edit/A_dvanced/Delete to end of line"),
588 compose_gtk_stext_action_cb,
589 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
591 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
592 {N_("/_Edit/_Wrap current paragraph"),
593 "<control>L", compose_wrap_line, 0, NULL},
594 {N_("/_Edit/Wrap all long _lines"),
595 "<control><alt>L", compose_wrap_line_all, 0, NULL},
596 {N_("/_Edit/Edit with e_xternal editor"),
597 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
599 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
600 {N_("/_Spelling/_Check all or check selection"),
601 NULL, compose_check_all, 0, NULL},
602 {N_("/_Spelling/_Highlight all misspelled words"),
603 NULL, compose_highlight_all, 0, NULL},
604 {N_("/_Spelling/Check _backwards misspelled word"),
605 NULL, compose_check_backwards , 0, NULL},
606 {N_("/_Spelling/_Forward to next misspelled word"),
607 NULL, compose_check_forwards_go, 0, NULL},
608 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
609 {N_("/_Spelling/_Spelling Configuration"),
610 NULL, NULL, 0, "<Branch>"},
612 #if 0 /* NEW COMPOSE GUI */
613 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
614 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
615 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
616 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
617 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
618 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
619 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
620 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
621 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
622 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
623 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
625 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
626 {N_("/_Message/_Send"), "<control>Return",
627 compose_send_cb, 0, NULL},
628 {N_("/_Message/Send _later"), "<shift><control>S",
629 compose_send_later_cb, 0, NULL},
630 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
631 {N_("/_Message/Save to _draft folder"),
632 "<shift><control>D", compose_draft_cb, 0, NULL},
633 {N_("/_Message/Save and _keep editing"),
634 "<control>S", compose_draft_cb, 1, NULL},
635 #if 0 /* NEW COMPOSE GUI */
636 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
637 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
638 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
639 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
640 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
641 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
642 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
643 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
644 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
647 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
648 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
649 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
650 {N_("/_Message/Mode/MIME"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_DETACH, "<RadioItem>"},
651 {N_("/_Message/Mode/Inline"), NULL, compose_set_gnupg_mode_cb, GNUPG_MODE_INLINE, "/Message/Mode/MIME"},
652 #endif /* USE_GPGME */
653 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
654 {N_("/_Message/_Priority"), NULL, NULL, 0, "<Branch>"},
655 {N_("/_Message/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
656 {N_("/_Message/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
657 {N_("/_Message/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
658 {N_("/_Message/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
659 {N_("/_Message/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
660 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
661 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
662 {N_("/_Message/Remo_ve references"), NULL, compose_toggle_remove_refs_cb, 0, "<ToggleItem>"},
663 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
664 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
665 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
666 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
667 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
668 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
669 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
672 static GtkTargetEntry compose_mime_types[] =
674 {"text/uri-list", 0, 0}
677 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
678 GPtrArray *attach_files)
680 return compose_generic_new(account, mailto, NULL, attach_files);
683 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
685 return compose_generic_new(account, NULL, item, NULL);
688 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
689 GPtrArray *attach_files)
693 GtkItemFactory *ifactory;
694 gboolean grab_focus_on_last = TRUE;
696 if (item && item->prefs && item->prefs->enable_default_account)
697 account = account_find_from_id(item->prefs->default_account);
699 if (!account) account = cur_account;
700 g_return_val_if_fail(account != NULL, NULL);
702 compose = compose_create(account, COMPOSE_NEW);
703 ifactory = gtk_item_factory_from_widget(compose->menubar);
705 compose->replyinfo = NULL;
706 compose->fwdinfo = NULL;
708 text = GTK_STEXT(compose->text);
709 gtk_stext_freeze(text);
711 if (account->auto_sig)
712 compose_insert_sig(compose, FALSE);
713 gtk_editable_set_position(GTK_EDITABLE(text), 0);
714 gtk_stext_set_point(text, 0);
716 gtk_stext_thaw(text);
718 if (account->protocol != A_NNTP) {
719 if (mailto && *mailto != '\0') {
720 compose_entries_set(compose, mailto);
722 } else if (item && item->prefs->enable_default_to) {
723 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
724 compose_entry_select(compose, item->prefs->default_to);
725 grab_focus_on_last = FALSE;
727 if (item && item->ret_rcpt) {
728 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
732 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
735 * CLAWS: just don't allow return receipt request, even if the user
736 * may want to send an email. simple but foolproof.
738 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
745 for (i = 0; i < attach_files->len; i++) {
746 file = g_ptr_array_index(attach_files, i);
747 compose_attach_append(compose, file, file, NULL);
751 compose_show_first_last_header(compose, TRUE);
753 /* Set save folder */
754 if (item && item->prefs && item->prefs->save_copy_to_folder) {
755 gchar *folderidentifier;
757 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
758 folderidentifier = folder_item_get_identifier(item);
759 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
760 g_free(folderidentifier);
763 /* Grab focus on last header only if no default_to was set */
764 if (grab_focus_on_last)
765 gtk_widget_grab_focus(compose->header_last->entry);
767 if (prefs_common.auto_exteditor)
768 compose_exec_ext_editor(compose);
774 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
775 const gchar *followupto, gchar * to)
779 if (!account) account = cur_account;
780 g_return_val_if_fail(account != NULL, NULL);
781 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
783 compose = compose_create(account, COMPOSE_NEW);
785 if (prefs_common.auto_sig)
786 compose_insert_sig(compose);
787 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
788 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
790 compose_entry_append(compose, to, COMPOSE_TO);
791 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
792 gtk_widget_grab_focus(compose->subject_entry);
798 void compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar *body)
803 g_return_if_fail(msginfo_list != NULL);
805 msginfo = (MsgInfo*)g_slist_nth_data(msginfo_list, 0);
806 g_return_if_fail(msginfo != NULL);
808 list_len = g_slist_length(msginfo_list);
812 compose_reply(msginfo, prefs_common.reply_with_quote,
813 FALSE, prefs_common.default_reply_list, FALSE, body);
815 case COMPOSE_REPLY_WITH_QUOTE:
816 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, body);
818 case COMPOSE_REPLY_WITHOUT_QUOTE:
819 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
821 case COMPOSE_REPLY_TO_SENDER:
822 compose_reply(msginfo, prefs_common.reply_with_quote,
823 FALSE, FALSE, TRUE, body);
825 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
826 compose_followup_and_reply_to(msginfo,
827 prefs_common.reply_with_quote,
830 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
831 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, body);
833 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
834 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
836 case COMPOSE_REPLY_TO_ALL:
837 compose_reply(msginfo, prefs_common.reply_with_quote,
838 TRUE, FALSE, FALSE, body);
840 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
841 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, body);
843 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
844 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
846 case COMPOSE_REPLY_TO_LIST:
847 compose_reply(msginfo, prefs_common.reply_with_quote,
848 FALSE, TRUE, FALSE, body);
850 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
851 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, body);
853 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
854 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
856 case COMPOSE_FORWARD:
857 if (prefs_common.forward_as_attachment) {
858 compose_reply_mode(COMPOSE_FORWARD_AS_ATTACH, msginfo_list, body);
861 compose_reply_mode(COMPOSE_FORWARD_INLINE, msginfo_list, body);
865 case COMPOSE_FORWARD_INLINE:
866 /* check if we reply to more than one Message */
868 compose_forward(NULL, msginfo, FALSE, body);
871 /* more messages FALL THROUGH */
872 case COMPOSE_FORWARD_AS_ATTACH:
873 compose_forward_multiple(NULL, msginfo_list);
875 case COMPOSE_REDIRECT:
876 compose_redirect(NULL, msginfo);
879 g_warning("compose_reply(): invalid Compose Mode: %d\n", mode);
883 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
884 gboolean to_ml, gboolean to_sender,
887 compose_generic_reply(msginfo, quote, to_all, to_ml,
888 to_sender, FALSE, body);
891 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
896 compose_generic_reply(msginfo, quote, to_all, FALSE,
897 to_sender, TRUE, body);
900 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
901 gboolean to_all, gboolean to_ml,
903 gboolean followup_and_reply_to,
906 GtkItemFactory *ifactory;
908 PrefsAccount *account = NULL;
909 PrefsAccount *reply_account;
912 g_return_if_fail(msginfo != NULL);
913 g_return_if_fail(msginfo->folder != NULL);
915 account = account_get_reply_account(msginfo, prefs_common.reply_account_autosel);
917 g_return_if_fail(account != NULL);
919 if (to_sender && account->protocol == A_NNTP &&
920 !followup_and_reply_to) {
922 account_find_from_address(account->address);
924 reply_account = compose_current_mail_account();
928 reply_account = account;
930 compose = compose_create(account, COMPOSE_REPLY);
931 ifactory = gtk_item_factory_from_widget(compose->menubar);
933 menu_set_toggle(ifactory, "/Message/Remove references", FALSE);
934 menu_set_sensitive(ifactory, "/Message/Remove references", TRUE);
936 compose->replyinfo = procmsg_msginfo_get_full_info(msginfo);
937 if (!compose->replyinfo)
938 compose->replyinfo = procmsg_msginfo_copy(msginfo);
940 if (msginfo->folder && msginfo->folder->ret_rcpt)
941 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
943 /* Set save folder */
944 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
945 gchar *folderidentifier;
947 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
948 folderidentifier = folder_item_get_identifier(msginfo->folder);
949 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
950 g_free(folderidentifier);
953 if (compose_parse_header(compose, msginfo) < 0) return;
954 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
955 to_sender, followup_and_reply_to);
956 compose_show_first_last_header(compose, TRUE);
958 text = GTK_STEXT(compose->text);
959 gtk_stext_freeze(text);
964 if (prefs_common.quotemark && *prefs_common.quotemark)
965 qmark = prefs_common.quotemark;
969 compose_quote_fmt(compose, compose->replyinfo,
970 prefs_common.quotefmt,
974 if (account->auto_sig)
975 compose_insert_sig(compose, FALSE);
977 if (quote && prefs_common.linewrap_quote)
978 compose_wrap_line_all(compose);
980 gtk_editable_set_position(GTK_EDITABLE(text), 0);
981 gtk_stext_set_point(text, 0);
983 gtk_stext_thaw(text);
984 gtk_widget_grab_focus(compose->text);
986 if (prefs_common.auto_exteditor)
987 compose_exec_ext_editor(compose);
990 #define INSERT_FW_HEADER(var, hdr) \
991 if (msginfo->var && *msginfo->var) { \
992 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
993 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
994 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
997 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
998 gboolean as_attach, const gchar *body)
1003 g_return_val_if_fail(msginfo != NULL, NULL);
1004 g_return_val_if_fail(msginfo->folder != NULL, NULL);
1006 if (msginfo->folder->prefs->enable_default_account)
1007 account = account_find_from_id(msginfo->folder->prefs->default_account);
1009 account = msginfo->folder->folder->account;
1010 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
1012 Xstrdup_a(to, msginfo->to, return NULL);
1013 extract_address(to);
1014 account = account_find_from_address(to);
1017 if (!account && prefs_common.forward_account_autosel) {
1019 if (!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
1020 extract_address(cc);
1021 account = account_find_from_address(cc);
1025 if (account == NULL) {
1026 account = cur_account;
1028 account = msginfo->folder->folder->account;
1029 if (!account) account = cur_account;
1032 g_return_val_if_fail(account != NULL, NULL);
1034 compose = compose_create(account, COMPOSE_FORWARD);
1036 compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
1037 if (!compose->fwdinfo)
1038 compose->fwdinfo = procmsg_msginfo_copy(msginfo);
1040 if (msginfo->subject && *msginfo->subject) {
1041 gchar *buf, *buf2, *p;
1043 buf = p = g_strdup(msginfo->subject);
1044 p += subject_get_prefix_length(p);
1045 memmove(buf, p, strlen(p) + 1);
1047 buf2 = g_strdup_printf("Fw: %s", buf);
1048 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1054 text = GTK_STEXT(compose->text);
1055 gtk_stext_freeze(text);
1060 msgfile = procmsg_get_message_file_path(msginfo);
1061 if (!is_file_exist(msgfile))
1062 g_warning("%s: file not exist\n", msgfile);
1064 compose_attach_append(compose, msgfile, msgfile,
1070 MsgInfo *full_msginfo;
1072 full_msginfo = procmsg_msginfo_get_full_info(msginfo);
1074 full_msginfo = procmsg_msginfo_copy(msginfo);
1076 if (prefs_common.fw_quotemark &&
1077 *prefs_common.fw_quotemark)
1078 qmark = prefs_common.fw_quotemark;
1082 compose_quote_fmt(compose, full_msginfo,
1083 prefs_common.fw_quotefmt,
1085 compose_attach_parts(compose, msginfo);
1087 procmsg_msginfo_free(full_msginfo);
1090 if (account->auto_sig)
1091 compose_insert_sig(compose, FALSE);
1093 if (prefs_common.linewrap_quote)
1094 compose_wrap_line_all(compose);
1096 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1097 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1099 gtk_stext_thaw(text);
1100 #if 0 /* NEW COMPOSE GUI */
1101 if (account->protocol != A_NNTP)
1102 gtk_widget_grab_focus(compose->to_entry);
1104 gtk_widget_grab_focus(compose->newsgroups_entry);
1106 gtk_widget_grab_focus(compose->header_last->entry);
1108 if (prefs_common.auto_exteditor)
1109 compose_exec_ext_editor(compose);
1112 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
1113 gchar *folderidentifier;
1115 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1116 folderidentifier = folder_item_get_identifier(msginfo->folder);
1117 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
1118 g_free(folderidentifier);
1124 #undef INSERT_FW_HEADER
1126 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1133 g_return_val_if_fail(msginfo_list != NULL, NULL);
1135 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1136 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1140 if (account == NULL) {
1141 account = cur_account;
1143 account = msginfo->folder->folder->account;
1144 if (!account) account = cur_account;
1147 g_return_val_if_fail(account != NULL, NULL);
1149 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1150 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1151 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1154 compose = compose_create(account, COMPOSE_FORWARD);
1156 text = GTK_STEXT(compose->text);
1157 gtk_stext_freeze(text);
1159 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1160 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1161 if (!is_file_exist(msgfile))
1162 g_warning("%s: file not exist\n", msgfile);
1164 compose_attach_append(compose, msgfile, msgfile,
1169 if (account->auto_sig)
1170 compose_insert_sig(compose, FALSE);
1172 if (prefs_common.linewrap_quote)
1173 compose_wrap_line_all(compose);
1175 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1176 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1178 gtk_stext_thaw(text);
1179 gtk_widget_grab_focus(compose->header_last->entry);
1181 #if 0 /* NEW COMPOSE GUI */
1182 if (account->protocol != A_NNTP)
1183 gtk_widget_grab_focus(compose->to_entry);
1185 gtk_widget_grab_focus(compose->newsgroups_entry);
1191 void compose_reedit(MsgInfo *msginfo)
1194 PrefsAccount *account = NULL;
1197 gchar buf[BUFFSIZE];
1199 g_return_if_fail(msginfo != NULL);
1200 g_return_if_fail(msginfo->folder != NULL);
1202 if (msginfo->folder->stype == F_QUEUE || msginfo->folder->stype == F_DRAFT) {
1203 gchar queueheader_buf[BUFFSIZE];
1206 /* Select Account from queue headers */
1207 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1208 sizeof(queueheader_buf), "X-Sylpheed-Account-Id:")) {
1209 id = atoi(&queueheader_buf[22]);
1210 account = account_find_from_id(id);
1212 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1213 sizeof(queueheader_buf), "NAID:")) {
1214 id = atoi(&queueheader_buf[5]);
1215 account = account_find_from_id(id);
1217 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1218 sizeof(queueheader_buf), "MAID:")) {
1219 id = atoi(&queueheader_buf[5]);
1220 account = account_find_from_id(id);
1222 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1223 sizeof(queueheader_buf), "S:")) {
1224 account = account_find_from_address(queueheader_buf);
1227 account = msginfo->folder->folder->account;
1229 if (!account && prefs_common.reedit_account_autosel) {
1230 gchar from[BUFFSIZE];
1231 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1232 extract_address(from);
1233 account = account_find_from_address(from);
1236 if (!account) account = cur_account;
1237 g_return_if_fail(account != NULL);
1239 compose = compose_create(account, COMPOSE_REEDIT);
1240 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1242 if (msginfo->folder->stype == F_QUEUE
1243 || msginfo->folder->stype == F_DRAFT) {
1244 gchar queueheader_buf[BUFFSIZE];
1246 /* Set message save folder */
1247 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1250 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1251 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1252 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1256 if (compose_parse_header(compose, msginfo) < 0) return;
1257 compose_reedit_set_entry(compose, msginfo);
1259 text = GTK_STEXT(compose->text);
1260 gtk_stext_freeze(text);
1262 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1263 g_warning("Can't get text part\n");
1265 while (fgets(buf, sizeof(buf), fp) != NULL) {
1267 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1271 compose_attach_parts(compose, msginfo);
1273 gtk_stext_thaw(text);
1274 gtk_widget_grab_focus(compose->text);
1276 if (prefs_common.auto_exteditor)
1277 compose_exec_ext_editor(compose);
1280 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1284 GtkItemFactory *ifactory;
1286 g_return_val_if_fail(msginfo != NULL, NULL);
1289 account = account_get_reply_account(msginfo,
1290 prefs_common.reply_account_autosel);
1291 g_return_val_if_fail(account != NULL, NULL);
1293 compose = compose_create(account, COMPOSE_REDIRECT);
1294 ifactory = gtk_item_factory_from_widget(compose->menubar);
1296 compose->replyinfo = NULL;
1297 compose->fwdinfo = NULL;
1299 compose_show_first_last_header(compose, TRUE);
1301 gtk_widget_grab_focus(compose->header_last->entry);
1303 filename = procmsg_get_message_file(msginfo);
1304 if (filename == NULL)
1307 compose->redirect_filename = filename;
1309 compose_attach_parts(compose, msginfo);
1311 if (msginfo->subject)
1312 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1314 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1316 gtk_stext_freeze(GTK_STEXT(compose->text));
1317 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1318 gtk_editable_set_editable(GTK_EDITABLE(compose->text), FALSE);
1319 gtk_stext_thaw(GTK_STEXT(compose->text));
1321 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1322 menu_set_sensitive(ifactory, "/Add...", FALSE);
1323 menu_set_sensitive(ifactory, "/Remove", FALSE);
1324 menu_set_sensitive(ifactory, "/Property...", FALSE);
1326 ifactory = gtk_item_factory_from_widget(compose->menubar);
1327 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
1328 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
1329 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
1330 menu_set_sensitive(ifactory, "/Edit", FALSE);
1331 menu_set_sensitive(ifactory, "/Message/Save to draft folder", FALSE);
1332 menu_set_sensitive(ifactory, "/Message/Save and keep editing", FALSE);
1334 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
1335 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
1336 menu_set_sensitive(ifactory, "/Message/Mode/MIME", FALSE);
1337 menu_set_sensitive(ifactory, "/Message/Mode/Inline", FALSE);
1339 menu_set_sensitive(ifactory, "/Message/Priority", FALSE);
1340 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
1341 menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
1342 menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
1344 gtk_widget_set_sensitive(compose->toolbar->draft_btn, FALSE);
1345 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1346 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1347 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1348 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1349 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, FALSE);
1354 GList *compose_get_compose_list(void)
1356 return compose_list;
1359 void compose_entry_append(Compose *compose, const gchar *address,
1360 ComposeEntryType type)
1364 if (!address || *address == '\0') return;
1366 #if 0 /* NEW COMPOSE GUI */
1369 entry = GTK_ENTRY(compose->cc_entry);
1372 entry = GTK_ENTRY(compose->bcc_entry);
1374 case COMPOSE_NEWSGROUPS:
1375 entry = GTK_ENTRY(compose->newsgroups_entry);
1379 entry = GTK_ENTRY(compose->to_entry);
1383 text = gtk_entry_get_text(entry);
1385 gtk_entry_append_text(entry, ", ");
1386 gtk_entry_append_text(entry, address);
1394 header = N_("Bcc:");
1396 case COMPOSE_REPLYTO:
1397 header = N_("Reply-To:");
1399 case COMPOSE_NEWSGROUPS:
1400 header = N_("Newsgroups:");
1402 case COMPOSE_FOLLOWUPTO:
1403 header = N_( "Followup-To:");
1410 header = prefs_common.trans_hdr ? gettext(header) : header;
1412 compose_add_header_entry(compose, header, (gchar *)address);
1415 void compose_entry_select (Compose *compose, const gchar *mailto)
1417 GSList *header_list;
1419 for (header_list = compose->header_list; header_list != NULL; header_list = header_list->next) {
1420 GtkEntry * entry = GTK_ENTRY(((ComposeHeaderEntry *)header_list->data)->entry);
1422 if (gtk_entry_get_text(entry) && !g_strcasecmp(gtk_entry_get_text(entry), mailto)) {
1423 gtk_entry_select_region(entry, 0, -1);
1424 gtk_widget_grab_focus(GTK_WIDGET(entry));
1429 void compose_toolbar_cb(gint action, gpointer data)
1431 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1432 Compose *compose = (Compose*)toolbar_item->parent;
1434 g_return_if_fail(compose != NULL);
1438 compose_send_cb(compose, 0, NULL);
1441 compose_send_later_cb(compose, 0, NULL);
1444 compose_draft_cb(compose, 0, NULL);
1447 compose_insert_file_cb(compose, 0, NULL);
1450 compose_attach_cb(compose, 0, NULL);
1453 compose_insert_sig(compose, FALSE);
1456 compose_ext_editor_cb(compose, 0, NULL);
1459 compose_wrap_line(compose);
1462 compose_address_cb(compose, 0, NULL);
1469 static void compose_entries_set(Compose *compose, const gchar *mailto)
1474 gchar *subject = NULL;
1477 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1480 compose_entry_append(compose, to, COMPOSE_TO);
1482 compose_entry_append(compose, cc, COMPOSE_CC);
1484 compose_entry_append(compose, bcc, COMPOSE_BCC);
1486 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1488 gtk_stext_insert(GTK_STEXT(compose->text),
1489 NULL, NULL, NULL, body, -1);
1490 gtk_stext_insert(GTK_STEXT(compose->text),
1491 NULL, NULL, NULL, "\n", 1);
1501 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1503 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1504 {"Cc:", NULL, TRUE},
1505 {"References:", NULL, FALSE},
1506 {"Bcc:", NULL, TRUE},
1507 {"Newsgroups:", NULL, TRUE},
1508 {"Followup-To:", NULL, TRUE},
1509 {"List-Post:", NULL, FALSE},
1510 {"X-Priority:", NULL, FALSE},
1511 {NULL, NULL, FALSE}};
1527 g_return_val_if_fail(msginfo != NULL, -1);
1529 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1530 procheader_get_header_fields(fp, hentry);
1533 if (hentry[H_REPLY_TO].body != NULL) {
1534 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1535 compose->replyto = hentry[H_REPLY_TO].body;
1536 hentry[H_REPLY_TO].body = NULL;
1538 if (hentry[H_CC].body != NULL) {
1539 conv_unmime_header_overwrite(hentry[H_CC].body);
1540 compose->cc = hentry[H_CC].body;
1541 hentry[H_CC].body = NULL;
1543 if (hentry[H_REFERENCES].body != NULL) {
1544 if (compose->mode == COMPOSE_REEDIT)
1545 compose->references = hentry[H_REFERENCES].body;
1547 compose->references = compose_parse_references
1548 (hentry[H_REFERENCES].body, msginfo->msgid);
1549 g_free(hentry[H_REFERENCES].body);
1551 hentry[H_REFERENCES].body = NULL;
1553 if (hentry[H_BCC].body != NULL) {
1554 if (compose->mode == COMPOSE_REEDIT) {
1555 conv_unmime_header_overwrite(hentry[H_BCC].body);
1556 compose->bcc = hentry[H_BCC].body;
1558 g_free(hentry[H_BCC].body);
1559 hentry[H_BCC].body = NULL;
1561 if (hentry[H_NEWSGROUPS].body != NULL) {
1562 conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
1563 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1564 hentry[H_NEWSGROUPS].body = NULL;
1566 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1567 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1568 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1569 hentry[H_FOLLOWUP_TO].body = NULL;
1571 if (hentry[H_LIST_POST].body != NULL) {
1574 extract_address(hentry[H_LIST_POST].body);
1575 if (hentry[H_LIST_POST].body[0] != '\0') {
1576 scan_mailto_url(hentry[H_LIST_POST].body,
1577 &to, NULL, NULL, NULL, NULL);
1579 g_free(compose->ml_post);
1580 compose->ml_post = to;
1583 g_free(hentry[H_LIST_POST].body);
1584 hentry[H_LIST_POST].body = NULL;
1587 /* CLAWS - X-Priority */
1588 if (compose->mode == COMPOSE_REEDIT)
1589 if (hentry[H_X_PRIORITY].body != NULL) {
1592 priority = atoi(hentry[H_X_PRIORITY].body);
1593 g_free(hentry[H_X_PRIORITY].body);
1595 hentry[H_X_PRIORITY].body = NULL;
1597 if (priority < PRIORITY_HIGHEST ||
1598 priority > PRIORITY_LOWEST)
1599 priority = PRIORITY_NORMAL;
1601 compose->priority = priority;
1604 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1605 compose->inreplyto = g_strdup(msginfo->inreplyto);
1606 else if (compose->mode != COMPOSE_REEDIT &&
1607 msginfo->msgid && *msginfo->msgid) {
1608 compose->inreplyto = g_strdup(msginfo->msgid);
1610 if (!compose->references) {
1611 if (msginfo->inreplyto && *msginfo->inreplyto)
1612 compose->references =
1613 g_strdup_printf("<%s>\n\t<%s>",
1617 compose->references =
1618 g_strconcat("<", msginfo->msgid, ">",
1626 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1628 GSList *ref_id_list, *cur;
1632 ref_id_list = references_list_append(NULL, ref);
1633 if (!ref_id_list) return NULL;
1634 if (msgid && *msgid)
1635 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1640 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1641 /* "<" + Message-ID + ">" + CR+LF+TAB */
1642 len += strlen((gchar *)cur->data) + 5;
1644 if (len > MAX_REFERENCES_LEN) {
1645 /* remove second message-ID */
1646 if (ref_id_list && ref_id_list->next &&
1647 ref_id_list->next->next) {
1648 g_free(ref_id_list->next->data);
1649 ref_id_list = g_slist_remove
1650 (ref_id_list, ref_id_list->next->data);
1652 slist_free_strings(ref_id_list);
1653 g_slist_free(ref_id_list);
1660 new_ref = g_string_new("");
1661 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1662 if (new_ref->len > 0)
1663 g_string_append(new_ref, "\n\t");
1664 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1667 slist_free_strings(ref_id_list);
1668 g_slist_free(ref_id_list);
1670 new_ref_str = new_ref->str;
1671 g_string_free(new_ref, FALSE);
1676 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1677 const gchar *fmt, const gchar *qmark,
1680 GtkSText *text = GTK_STEXT(compose->text);
1681 static MsgInfo dummyinfo;
1682 gchar *quote_str = NULL;
1686 const gchar *trimmed_body = body;
1689 msginfo = &dummyinfo;
1691 if (qmark != NULL) {
1692 quote_fmt_init(msginfo, NULL, NULL);
1693 quote_fmt_scan_string(qmark);
1696 buf = quote_fmt_get_buffer();
1698 alertpanel_error(_("Quote mark format error."));
1700 Xstrdup_a(quote_str, buf, return NULL)
1703 if (fmt && *fmt != '\0') {
1704 while (trimmed_body && strlen(trimmed_body) > 1
1705 && trimmed_body[0]=='\n')
1708 quote_fmt_init(msginfo, quote_str, trimmed_body);
1709 quote_fmt_scan_string(fmt);
1712 buf = quote_fmt_get_buffer();
1714 alertpanel_error(_("Message reply/forward format error."));
1720 gtk_stext_freeze(text);
1722 for (p = buf; *p != '\0'; ) {
1723 lastp = strchr(p, '\n');
1724 len = lastp ? lastp - p + 1 : -1;
1725 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1732 gtk_stext_thaw(text);
1737 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1738 gboolean to_all, gboolean to_ml,
1740 gboolean followup_and_reply_to)
1742 GSList *cc_list = NULL;
1745 gchar *replyto = NULL;
1746 GHashTable *to_table;
1748 g_return_if_fail(compose->account != NULL);
1749 g_return_if_fail(msginfo != NULL);
1751 if (compose->account->protocol != A_NNTP) {
1752 if (!compose->replyto && to_ml && compose->ml_post
1753 && !(msginfo->folder && msginfo->folder->prefs->enable_default_reply_to))
1754 compose_entry_append(compose,
1757 else if (!(to_all || to_sender)
1759 && msginfo->folder->prefs->enable_default_reply_to) {
1760 compose_entry_append(compose,
1761 msginfo->folder->prefs->default_reply_to,
1764 compose_entry_append(compose,
1765 (compose->replyto && !to_sender)
1766 ? compose->replyto :
1767 msginfo->from ? msginfo->from : "",
1770 if (to_sender || (compose->followup_to &&
1771 !strncmp(compose->followup_to, "poster", 6)))
1772 compose_entry_append
1774 (compose->replyto ? compose->replyto :
1775 msginfo->from ? msginfo->from : ""),
1778 else if (followup_and_reply_to || to_all) {
1779 compose_entry_append
1781 (compose->replyto ? compose->replyto :
1782 msginfo->from ? msginfo->from : ""),
1785 compose_entry_append
1787 compose->followup_to ? compose->followup_to :
1788 compose->newsgroups ? compose->newsgroups : "",
1789 COMPOSE_NEWSGROUPS);
1792 compose_entry_append
1794 compose->followup_to ? compose->followup_to :
1795 compose->newsgroups ? compose->newsgroups : "",
1796 COMPOSE_NEWSGROUPS);
1799 if (msginfo->subject && *msginfo->subject) {
1800 gchar *buf, *buf2, *p;
1802 buf = p = g_strdup(msginfo->subject);
1803 p += subject_get_prefix_length(p);
1804 memmove(buf, p, strlen(p) + 1);
1806 buf2 = g_strdup_printf("Re: %s", buf);
1807 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1812 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1814 if (to_ml && compose->ml_post) return;
1815 if (!to_all || compose->account->protocol == A_NNTP) return;
1817 if (compose->replyto) {
1818 Xstrdup_a(replyto, compose->replyto, return);
1819 extract_address(replyto);
1821 if (msginfo->from) {
1822 Xstrdup_a(from, msginfo->from, return);
1823 extract_address(from);
1826 if (replyto && from)
1827 cc_list = address_list_append_with_comments(cc_list, from);
1828 cc_list = address_list_append_with_comments(cc_list, msginfo->to);
1829 cc_list = address_list_append_with_comments(cc_list, compose->cc);
1831 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1833 g_hash_table_insert(to_table, g_strdup(replyto), GINT_TO_POINTER(1));
1834 if (compose->account)
1835 g_hash_table_insert(to_table, g_strdup(compose->account->address),
1836 GINT_TO_POINTER(1));
1838 /* remove address on To: and that of current account */
1839 for (cur = cc_list; cur != NULL; ) {
1840 GSList *next = cur->next;
1843 addr = g_strdup(cur->data);
1844 extract_address(addr);
1846 if (GPOINTER_TO_INT(g_hash_table_lookup(to_table, addr)) == 1)
1847 cc_list = g_slist_remove(cc_list, cur->data);
1849 g_hash_table_insert(to_table, addr, GINT_TO_POINTER(1));
1853 hash_free_strings(to_table);
1854 g_hash_table_destroy(to_table);
1857 for (cur = cc_list; cur != NULL; cur = cur->next)
1858 compose_entry_append(compose, (gchar *)cur->data,
1860 slist_free_strings(cc_list);
1861 g_slist_free(cc_list);
1866 #define SET_ENTRY(entry, str) \
1869 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1872 #define SET_ADDRESS(type, str) \
1875 compose_entry_append(compose, str, type); \
1878 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1880 g_return_if_fail(msginfo != NULL);
1882 SET_ENTRY(subject_entry, msginfo->subject);
1883 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1884 SET_ADDRESS(COMPOSE_CC, compose->cc);
1885 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1886 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1887 SET_ADDRESS(COMPOSE_NEWSGROUPS, compose->newsgroups);
1888 SET_ADDRESS(COMPOSE_FOLLOWUPTO, compose->followup_to);
1890 compose_update_priority_menu_item(compose);
1892 compose_update_gnupg_mode_menu_item(compose);
1894 compose_show_first_last_header(compose, TRUE);
1901 static void compose_insert_sig(Compose *compose, gboolean replace)
1903 GtkSText *text = GTK_STEXT(compose->text);
1906 g_return_if_fail(compose->account != NULL);
1908 cur_pos = gtk_editable_get_position(GTK_EDITABLE(text));
1910 gtk_stext_freeze(text);
1912 if (replace && compose->sig_str) {
1916 if (compose->sig_str[0] == '\0')
1919 pos = gtkut_stext_find(text, 0, compose->sig_str, TRUE);
1922 len = get_mbs_len(compose->sig_str);
1924 gtk_stext_set_point(text, pos);
1925 gtk_stext_forward_delete(text, len);
1927 len = gtk_stext_get_length(text);
1928 gtk_stext_set_point(text, len);
1931 len = gtk_stext_get_length(text);
1932 gtk_stext_set_point(text, len);
1935 gtk_stext_insert(text, NULL, NULL, NULL, "\n\n", 2);
1937 g_free(compose->sig_str);
1938 compose->sig_str = compose_get_signature_str(compose);
1939 if (!compose->sig_str || (replace && !compose->account->auto_sig))
1940 compose->sig_str = g_strdup("");
1942 gtk_stext_insert(text, NULL, NULL, NULL, compose->sig_str, -1);
1944 gtk_stext_thaw(text);
1946 if (cur_pos > gtk_stext_get_length(text))
1947 cur_pos = gtk_stext_get_length(text);
1949 gtk_editable_set_position(GTK_EDITABLE(text), cur_pos);
1950 gtk_stext_set_point(text, cur_pos);
1953 static gchar *compose_get_signature_str(Compose *compose)
1955 gchar *sig_body = NULL;
1956 gchar *sig_str = NULL;
1958 g_return_val_if_fail(compose->account != NULL, NULL);
1960 if (!compose->account->sig_path)
1963 if (compose->account->sig_type == SIG_FILE) {
1964 if (!is_file_or_fifo_exist(compose->account->sig_path)) {
1965 g_warning("can't open signature file: %s\n",
1966 compose->account->sig_path);
1971 if (compose->account->sig_type == SIG_COMMAND)
1972 sig_body = get_command_output(compose->account->sig_path);
1976 tmp = file_read_to_str(compose->account->sig_path);
1979 sig_body = normalize_newlines(tmp);
1983 if (compose->account->sig_sep) {
1984 sig_str = g_strconcat(compose->account->sig_sep, "\n", sig_body,
1993 static void compose_insert_file(Compose *compose, const gchar *file)
1995 GtkSText *text = GTK_STEXT(compose->text);
1996 gchar buf[BUFFSIZE];
2000 g_return_if_fail(file != NULL);
2002 if ((fp = fopen(file, "rb")) == NULL) {
2003 FILE_OP_ERROR(file, "fopen");
2007 gtk_stext_freeze(text);
2009 while (fgets(buf, sizeof(buf), fp) != NULL) {
2010 /* strip <CR> if DOS/Windows file,
2011 replace <CR> with <LF> if Macintosh file. */
2014 if (len > 0 && buf[len - 1] != '\n') {
2016 if (buf[len] == '\r') buf[len] = '\n';
2018 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
2021 gtk_stext_thaw(text);
2026 static void compose_attach_append(Compose *compose, const gchar *file,
2027 const gchar *filename,
2028 const gchar *content_type)
2031 gchar *text[N_ATTACH_COLS];
2036 if (!is_file_exist(file)) {
2037 g_warning("File %s doesn't exist\n", file);
2040 if ((size = get_file_size(file)) < 0) {
2041 g_warning("Can't get file size of %s\n", file);
2045 alertpanel_notice(_("File %s is empty."), file);
2048 if ((fp = fopen(file, "rb")) == NULL) {
2049 alertpanel_error(_("Can't read %s."), file);
2054 #if 0 /* NEW COMPOSE GUI */
2055 if (!compose->use_attach) {
2056 GtkItemFactory *ifactory;
2057 GtkWidget *menuitem;
2059 ifactory = gtk_item_factory_from_widget(compose->menubar);
2060 menuitem = gtk_item_factory_get_item(ifactory,
2061 "/View/Attachment");
2062 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2066 ainfo = g_new0(AttachInfo, 1);
2067 ainfo->file = g_strdup(file);
2070 ainfo->content_type = g_strdup(content_type);
2071 if (!strcasecmp(content_type, "message/rfc822")) {
2073 MsgFlags flags = {0, 0};
2076 if (procmime_get_encoding_for_file(file) == ENC_7BIT)
2077 ainfo->encoding = ENC_7BIT;
2079 ainfo->encoding = ENC_8BIT;
2081 msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
2082 if (msginfo && msginfo->subject)
2083 name = msginfo->subject;
2085 name = g_basename(filename ? filename : file);
2087 ainfo->name = g_strdup_printf(_("Message: %s"), name);
2089 procmsg_msginfo_free(msginfo);
2091 if (!g_strncasecmp(content_type, "text", 4))
2093 procmime_get_encoding_for_file(file);
2095 ainfo->encoding = ENC_BASE64;
2096 ainfo->name = g_strdup
2097 (g_basename(filename ? filename : file));
2100 ainfo->content_type = procmime_get_mime_type(file);
2101 if (!ainfo->content_type) {
2102 ainfo->content_type =
2103 g_strdup("application/octet-stream");
2104 ainfo->encoding = ENC_BASE64;
2105 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
2106 ainfo->encoding = procmime_get_encoding_for_file(file);
2108 ainfo->encoding = ENC_BASE64;
2109 ainfo->name = g_strdup(g_basename(filename ? filename : file));
2113 text[COL_MIMETYPE] = ainfo->content_type;
2114 text[COL_SIZE] = to_human_readable(size);
2115 text[COL_NAME] = ainfo->name;
2117 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
2118 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
2121 #define IS_FIRST_PART_TEXT(info) \
2122 ((info->mime_type == MIME_TEXT || info->mime_type == MIME_TEXT_HTML || \
2123 info->mime_type == MIME_TEXT_ENRICHED) || \
2124 (info->mime_type == MIME_MULTIPART && info->content_type && \
2125 !strcasecmp(info->content_type, "multipart/alternative") && \
2126 (info->children && \
2127 (info->children->mime_type == MIME_TEXT || \
2128 info->children->mime_type == MIME_TEXT_HTML || \
2129 info->children->mime_type == MIME_TEXT_ENRICHED))))
2131 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
2138 mimeinfo = procmime_scan_message(msginfo);
2139 if (!mimeinfo) return;
2141 /* skip first text (presumably message body) */
2142 child = mimeinfo->children;
2143 if (!child || IS_FIRST_PART_TEXT(mimeinfo)) {
2144 procmime_mimeinfo_free_all(mimeinfo);
2148 if (IS_FIRST_PART_TEXT(child))
2149 child = child->next;
2151 infile = procmsg_get_message_file_path(msginfo);
2153 while (child != NULL) {
2154 if (child->children || child->mime_type == MIME_MULTIPART) {
2155 child = procmime_mimeinfo_next(child);
2158 if (child->parent && child->parent->parent
2159 && !strcasecmp(child->parent->parent->content_type, "multipart/signed")
2160 && child->mime_type == MIME_TEXT) {
2161 /* this is the main text part of a signed message */
2162 child = procmime_mimeinfo_next(child);
2165 outfile = procmime_get_tmp_file_name(child);
2166 if (procmime_get_part(outfile, infile, child) < 0)
2167 g_warning("Can't get the part of multipart message.");
2168 else if (compose->mode != COMPOSE_REEDIT || strcmp(child->content_type, "application/pgp-signature"))
2169 compose_attach_append
2171 child->filename ? child->filename : child->name,
2172 child->content_type);
2174 child = child->next;
2178 procmime_mimeinfo_free_all(mimeinfo);
2181 #undef IS_FIRST_PART_TEXT
2183 #define GET_CHAR(pos, buf, len) \
2185 if (text->use_wchar) \
2186 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2188 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2193 #define DISP_WIDTH(len) \
2194 ((len > 2 && conv_get_current_charset() == C_UTF_8) ? 2 : \
2195 (len == 2 && conv_get_current_charset() == C_UTF_8) ? 1 : len)
2197 #define INDENT_CHARS ">|#"
2198 #define SPACE_CHARS " \t"
2200 static void compose_wrap_line(Compose *compose)
2202 GtkSText *text = GTK_STEXT(compose->text);
2203 gint ch_len, last_ch_len;
2204 gchar cbuf[MB_LEN_MAX], last_ch;
2208 gint p_start, p_end;
2209 gint line_pos, cur_pos;
2210 gint line_len, cur_len;
2212 gtk_stext_freeze(text);
2214 text_len = gtk_stext_get_length(text);
2216 /* check to see if the point is on the paragraph mark (empty line). */
2217 cur_pos = gtk_stext_get_point(text);
2218 GET_CHAR(cur_pos, cbuf, ch_len);
2219 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2221 goto compose_end; /* on the paragraph mark */
2222 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2223 if (ch_len == 1 && *cbuf == '\n')
2224 goto compose_end; /* on the paragraph mark */
2227 /* find paragraph start. */
2228 line_end = quoted = 0;
2229 for (p_start = cur_pos; p_start >= 0; --p_start) {
2230 GET_CHAR(p_start, cbuf, ch_len);
2231 if (ch_len == 1 && *cbuf == '\n') {
2233 goto compose_end; /* quoted part */
2241 && strchr(prefs_common.quote_chars, *cbuf))
2243 else if (ch_len != 1 || !isspace(*cbuf))
2252 /* find paragraph end. */
2254 for (p_end = cur_pos; p_end < text_len; p_end++) {
2255 GET_CHAR(p_end, cbuf, ch_len);
2256 if (ch_len == 1 && *cbuf == '\n') {
2263 if (line_end && ch_len == 1 &&
2264 strchr(prefs_common.quote_chars, *cbuf))
2265 goto compose_end; /* quoted part */
2270 if (p_end >= text_len)
2273 if (p_start >= p_end)
2276 line_len = cur_len = 0;
2280 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2283 GET_CHAR(cur_pos, cbuf, ch_len);
2290 if (ch_len == 1 && isspace(*cbuf))
2293 if (ch_len == 1 && *cbuf == '\n') {
2295 if (last_ch_len == 1 && !isspace(last_ch)) {
2296 if (cur_pos + 1 < p_end) {
2297 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2298 if (ch_len == 1 && !isspace(*cbuf))
2302 gtk_stext_set_point(text, cur_pos + 1);
2303 gtk_stext_backward_delete(text, 1);
2305 gtk_stext_set_point(text, cur_pos);
2306 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2316 last_ch_len = ch_len;
2320 line_pos = cur_pos + 1;
2321 line_len = cur_len + ch_len;
2324 if (cur_len + DISP_WIDTH(ch_len) > prefs_common.linewrap_len &&
2328 GET_CHAR(line_pos - 1, cbuf, ch_len);
2329 if (ch_len == 1 && isspace(*cbuf)) {
2330 gtk_stext_set_point(text, line_pos);
2331 gtk_stext_backward_delete(text, 1);
2340 gtk_stext_set_point(text, line_pos);
2341 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2345 cur_len = cur_len - line_len + DISP_WIDTH(ch_len);
2351 line_pos = cur_pos + 1;
2352 line_len = cur_len + DISP_WIDTH(ch_len);
2354 cur_len += DISP_WIDTH(ch_len);
2358 gtk_stext_thaw(text);
2363 /* Darko: used when I debug wrapping */
2364 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2367 gchar cbuf[MB_LEN_MAX];
2369 printf("%d [", pos);
2370 for (i = pos; i < tlen; i++) {
2371 GET_CHAR(i, cbuf, clen);
2372 if (clen < 0) break;
2373 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2375 fwrite(cbuf, clen, 1, stdout);
2383 WAIT_FOR_INDENT_CHAR,
2384 WAIT_FOR_INDENT_CHAR_OR_SPACE
2387 /* return indent length, we allow:
2388 > followed by spaces/tabs
2389 | followed by spaces/tabs
2390 uppercase characters immediately followed by >,
2391 and the repeating sequences of the above */
2392 /* return indent length */
2393 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2396 guint i, ch_len, alnum_cnt = 0;
2397 IndentState state = WAIT_FOR_INDENT_CHAR;
2398 gchar cbuf[MB_LEN_MAX];
2402 if (prefs_common.quote_chars == NULL) {
2406 for (i = start_pos; i < text_len; i++) {
2407 GET_CHAR(i, cbuf, ch_len);
2411 if (cbuf[0] == '\n')
2414 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2415 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2418 case WAIT_FOR_SPACE:
2419 if (is_space == FALSE)
2421 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2423 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2424 if (is_indent == FALSE && is_space == FALSE &&
2427 if (is_space == TRUE) {
2429 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2430 } else if (is_indent == TRUE) {
2432 state = WAIT_FOR_SPACE;
2435 state = WAIT_FOR_INDENT_CHAR;
2438 case WAIT_FOR_INDENT_CHAR:
2439 if (is_indent == FALSE && !isupper(cbuf[0]))
2441 if (is_indent == TRUE) {
2443 && !strchr(prefs_common.quote_chars, cbuf[0]))
2446 state = WAIT_FOR_SPACE;
2457 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2463 /* insert quotation string when line was wrapped */
2464 static guint ins_quote(GtkSText *text, guint indent_len,
2465 guint prev_line_pos, guint text_len,
2468 guint i, ins_len = 0;
2472 for (i = 0; i < indent_len; i++) {
2473 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2474 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2476 ins_len = indent_len;
2482 /* check if we should join the next line */
2483 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2484 guint prev_ilen, gboolean autowrap)
2486 guint indent_len, ch_len;
2487 gboolean do_join = FALSE;
2488 gchar cbuf[MB_LEN_MAX];
2490 indent_len = get_indent_length(text, start_pos, tlen);
2492 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2493 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2494 if (ch_len > 0 && (cbuf[0] != '\n'))
2501 static void compose_wrap_line_all(Compose *compose)
2503 compose_wrap_line_all_full(compose, FALSE);
2506 #define STEXT_FREEZE() \
2507 if (!frozen) { gtk_stext_freeze(text); frozen = TRUE; }
2509 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2511 GtkSText *text = GTK_STEXT(compose->text);
2513 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2514 gint line_len = 0, cur_len = 0;
2516 gboolean is_new_line = TRUE, do_delete = FALSE;
2518 gboolean linewrap_quote = TRUE;
2519 gboolean set_editable_pos = FALSE;
2520 gint editable_pos = 0;
2521 gboolean frozen = FALSE;
2522 guint linewrap_len = prefs_common.linewrap_len;
2523 gchar *qfmt = prefs_common.quotemark;
2524 gchar cbuf[MB_LEN_MAX];
2526 tlen = gtk_stext_get_length(text);
2528 for (; cur_pos < tlen; cur_pos++) {
2529 /* mark position of new line - needed for quotation wrap */
2532 i_len = get_indent_length(text, cur_pos, tlen);
2534 is_new_line = FALSE;
2537 g_print("new line i_len=%d p_pos=", i_len);
2538 dump_text(text, p_pos, tlen, 1);
2542 GET_CHAR(cur_pos, cbuf, ch_len);
2544 /* fix line length for tabs */
2545 if (ch_len == 1 && *cbuf == '\t') {
2546 guint tab_width = text->default_tab_width;
2547 guint tab_offset = line_len % tab_width;
2550 g_print("found tab at pos=%d line_len=%d ", cur_pos,
2554 line_len += tab_width - tab_offset - 1;
2558 printf("new_len=%d\n", line_len);
2562 /* we have encountered line break */
2563 if (ch_len == 1 && *cbuf == '\n') {
2565 gchar cb[MB_LEN_MAX];
2567 /* should we join the next line */
2568 if ((autowrap || i_len != cur_len) && do_delete &&
2570 (text, cur_pos + 1, tlen, i_len, autowrap))
2576 g_print("found CR at %d do_del is %d next line is ",
2577 cur_pos, do_delete);
2578 dump_text(text, cur_pos + 1, tlen, 1);
2581 /* skip delete if it is continuous URL */
2582 if (do_delete && (line_pos - p_pos <= i_len) &&
2583 gtk_stext_is_uri_string(text, line_pos, tlen))
2587 g_print("l_len=%d wrap_len=%d do_del=%d\n",
2588 line_len, linewrap_len, do_delete);
2590 /* should we delete to perform smart wrapping */
2591 if (line_len < linewrap_len && do_delete) {
2593 /* get rid of newline */
2594 gtk_stext_set_point(text, cur_pos);
2595 gtk_stext_forward_delete(text, 1);
2598 /* if text starts with quote fmt or with
2599 indent string, delete them */
2602 ilen = gtk_stext_str_compare_n
2603 (text, cur_pos, p_pos, i_len,
2606 gtk_stext_forward_delete
2612 GET_CHAR(cur_pos, cb, clen);
2614 /* insert space if it's alphanumeric */
2615 if ((cur_pos != line_pos) &&
2616 ((clen > 1) || isalnum(cb[0]))) {
2617 gtk_stext_insert(text, NULL, NULL,
2622 /* and start over with current line */
2623 cur_pos = p_pos - 1;
2625 line_len = cur_len = 0;
2629 g_print("after delete l_pos=");
2630 dump_text(text, line_pos, tlen, 1);
2632 /* move beginning of line if we are on LF */
2633 GET_CHAR(line_pos, cb, clen);
2634 if (clen == 1 && *cb == '\n')
2637 g_print("new line_pos=%d\n", line_pos);
2643 /* mark new line beginning */
2644 line_pos = cur_pos + 1;
2645 line_len = cur_len = 0;
2656 /* possible line break */
2657 if (ch_len == 1 && isspace(*cbuf)) {
2658 line_pos = cur_pos + 1;
2659 line_len = cur_len + ch_len;
2662 /* are we over wrapping length set in preferences ? */
2663 if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
2667 g_print("should wrap cur_pos=%d ", cur_pos);
2668 dump_text(text, p_pos, tlen, 1);
2669 dump_text(text, line_pos, tlen, 1);
2671 /* force wrapping if it is one long word but not URL */
2672 if (line_pos - p_pos <= i_len)
2673 if (!gtk_stext_is_uri_string
2674 (text, line_pos, tlen))
2675 line_pos = cur_pos - 1;
2677 g_print("new line_pos=%d\n", line_pos);
2680 GET_CHAR(line_pos - 1, cbuf, clen);
2682 /* if next character is space delete it */
2683 if (clen == 1 && isspace(*cbuf)) {
2684 if (p_pos + i_len != line_pos ||
2685 !gtk_stext_is_uri_string
2686 (text, line_pos, tlen)) {
2688 /* workaround for correct cursor
2690 if (set_editable_pos == FALSE) {
2691 editable_pos = gtk_editable_get_position(GTK_EDITABLE(text));
2692 if (editable_pos == line_pos)
2693 set_editable_pos = TRUE;
2695 gtk_stext_set_point(text, line_pos);
2696 gtk_stext_backward_delete(text, 1);
2705 /* if it is URL at beginning of line don't wrap */
2706 if (p_pos + i_len == line_pos &&
2707 gtk_stext_is_uri_string(text, line_pos, tlen)) {
2709 g_print("found URL at ");
2710 dump_text(text, line_pos, tlen, 1);
2717 gtk_stext_set_point(text, line_pos);
2718 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2719 gtk_stext_compact_buffer(text);
2722 /* for loop will increase it */
2723 cur_pos = line_pos - 1;
2724 /* start over with current line */
2726 line_len = cur_len = 0;
2727 if (autowrap || i_len > 0)
2732 g_print("after CR insert ");
2733 dump_text(text, line_pos, tlen, 1);
2734 dump_text(text, cur_pos, tlen, 1);
2737 /* should we insert quotation ? */
2738 if (linewrap_quote && i_len) {
2739 /* only if line is not already quoted */
2740 if (!gtk_stext_str_compare
2741 (text, line_pos, tlen, qfmt)) {
2744 if (line_pos - p_pos > i_len) {
2746 (text, i_len, p_pos,
2751 g_print("after quote insert ");
2752 dump_text(text, line_pos, tlen, 1);
2760 line_pos = cur_pos + 1;
2761 line_len = cur_len + DISP_WIDTH(ch_len);
2763 /* advance to next character in buffer */
2764 cur_len += DISP_WIDTH(ch_len);
2768 gtk_stext_thaw(text);
2770 if (set_editable_pos && editable_pos <= tlen)
2771 gtk_editable_set_position(GTK_EDITABLE(text), editable_pos);
2777 static void compose_set_title(Compose *compose)
2782 edited = compose->modified ? _(" [Edited]") : "";
2783 if (compose->account && compose->account->address)
2784 str = g_strdup_printf(_("%s - Compose message%s"),
2785 compose->account->address, edited);
2787 str = g_strdup_printf(_("Compose message%s"), edited);
2788 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2793 * compose_current_mail_account:
2795 * Find a current mail account (the currently selected account, or the
2796 * default account, if a news account is currently selected). If a
2797 * mail account cannot be found, display an error message.
2799 * Return value: Mail account, or NULL if not found.
2801 static PrefsAccount *
2802 compose_current_mail_account(void)
2806 if (cur_account && cur_account->protocol != A_NNTP)
2809 ac = account_get_default();
2810 if (!ac || ac->protocol == A_NNTP) {
2811 alertpanel_error(_("Account for sending mail is not specified.\n"
2812 "Please select a mail account before sending."));
2819 static void compose_select_account(Compose *compose, PrefsAccount *account,
2822 GtkWidget *menuitem;
2823 GtkItemFactory *ifactory;
2825 g_return_if_fail(account != NULL);
2827 compose->account = account;
2829 compose_set_title(compose);
2831 ifactory = gtk_item_factory_from_widget(compose->menubar);
2833 if (account->protocol == A_NNTP) {
2834 gtk_widget_show(compose->newsgroups_hbox);
2835 gtk_widget_show(compose->newsgroups_entry);
2836 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
2837 compose->use_newsgroups = TRUE;
2839 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2840 gtk_check_menu_item_set_active
2841 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2842 gtk_widget_set_sensitive(menuitem, TRUE);
2843 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2844 gtk_check_menu_item_set_active
2845 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2846 gtk_widget_set_sensitive(menuitem, TRUE);
2848 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
2850 gtk_widget_hide(compose->newsgroups_hbox);
2851 gtk_widget_hide(compose->newsgroups_entry);
2852 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
2853 gtk_widget_queue_resize(compose->table_vbox);
2854 compose->use_newsgroups = FALSE;
2856 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2857 gtk_check_menu_item_set_active
2858 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2859 gtk_widget_set_sensitive(menuitem, FALSE);
2860 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2861 gtk_check_menu_item_set_active
2862 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2863 gtk_widget_set_sensitive(menuitem, FALSE);
2865 menuitem = gtk_item_factory_get_item(ifactory, "/View/Followup to");
2866 gtk_check_menu_item_set_active
2867 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2868 gtk_widget_set_sensitive(menuitem, FALSE);
2871 if (account->set_autocc) {
2872 compose_entry_show(compose, COMPOSE_ENTRY_CC);
2873 if (account->auto_cc && compose->mode != COMPOSE_REEDIT)
2874 compose_entry_set(compose, account->auto_cc,
2877 if (account->set_autobcc) {
2878 compose_entry_show(compose, COMPOSE_ENTRY_BCC);
2879 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
2880 compose_entry_set(compose, account->auto_bcc,
2883 if (account->set_autoreplyto) {
2884 compose_entry_show(compose, COMPOSE_ENTRY_REPLY_TO);
2885 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
2886 compose_entry_set(compose, account->auto_replyto,
2887 COMPOSE_ENTRY_REPLY_TO);
2890 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
2891 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2892 prefs_common.show_ruler);
2896 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
2897 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2898 account->default_sign);
2899 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
2900 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2901 account->default_encrypt);
2903 activate_gnupg_mode(compose, account);
2904 #endif /* USE_GPGME */
2906 if (!init && compose->mode != COMPOSE_REDIRECT)
2907 compose_insert_sig(compose, TRUE);
2910 gboolean compose_check_for_valid_recipient(Compose *compose) {
2911 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2912 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2913 gboolean recipient_found = FALSE;
2917 /* free to and newsgroup list */
2918 slist_free_strings(compose->to_list);
2919 g_slist_free(compose->to_list);
2920 compose->to_list = NULL;
2922 slist_free_strings(compose->newsgroup_list);
2923 g_slist_free(compose->newsgroup_list);
2924 compose->newsgroup_list = NULL;
2926 /* search header entries for to and newsgroup entries */
2927 for (list = compose->header_list; list; list = list->next) {
2930 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
2931 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2933 if (entry[0] != '\0') {
2934 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2935 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2936 compose->to_list = address_list_append(compose->to_list, entry);
2937 recipient_found = TRUE;
2940 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2941 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2942 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2943 recipient_found = TRUE;
2950 return recipient_found;
2953 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
2957 if (compose_check_for_valid_recipient(compose) == FALSE) {
2958 alertpanel_error(_("Recipient is not specified."));
2962 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2963 if (*str == '\0' && check_subject == TRUE) {
2966 aval = alertpanel(_("Send"),
2967 _("Subject is empty. Send it anyway?"),
2968 _("Yes"), _("No"), NULL);
2969 if (aval != G_ALERTDEFAULT)
2976 gint compose_send(Compose *compose)
2983 if (compose_check_entries(compose, TRUE) == FALSE)
2986 val = compose_queue(compose, &msgnum, &folder);
2988 alertpanel_error(_("Could not queue message for sending"));
2993 alertpanel_error(_("The message was queued but could not be sent.\nUse \"Send queued messages\" from the main window to retry."));
2997 msgpath = folder_item_fetch_msg(folder, msgnum);
2998 val = procmsg_send_message_queue(msgpath);
3001 folder_item_remove_msg(folder, msgnum);
3006 #if 0 /* compose restructure */
3007 gint compose_send(Compose *compose)
3009 gchar tmp[MAXPATHLEN + 1];
3011 static gboolean lock = FALSE;
3015 g_return_val_if_fail(compose->account != NULL, -1);
3019 if (compose_check_entries(compose, TRUE) == FALSE) {
3024 /* write to temporary file */
3025 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
3026 get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
3028 if (prefs_common.linewrap_at_send)
3029 compose_wrap_line_all(compose);
3031 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
3036 if (!compose->to_list && !compose->newsgroup_list) {
3037 g_warning("can't get recipient list.");
3043 if (compose->to_list) {
3046 #if 0 /* NEW COMPOSE GUI */
3047 if (compose->account->protocol != A_NNTP)
3048 ac = compose->account;
3050 ac = account_find_from_address(compose->account->address);
3052 if (cur_account && cur_account->protocol != A_NNTP)
3055 ac = account_get_default();
3057 if (!ac || ac->protocol == A_NNTP) {
3058 alertpanel_error(_("Account for sending mail is not specified.\n"
3059 "Please select a mail account before sending."));
3066 ac = compose->account;
3068 ok = send_message(tmp, ac, compose->to_list);
3071 if (ok == 0 && compose->newsgroup_list) {
3072 ok = news_post(FOLDER(compose->account->folder), tmp);
3074 alertpanel_error(_("Error occurred while posting the message to %s ."),
3075 compose->account->nntp_server);
3082 /* queue message if failed to send */
3084 if (prefs_common.queue_msg) {
3089 _("Error occurred while sending the message.\n"
3090 "Put this message into queue folder?"),
3091 _("OK"), _("Cancel"), NULL);
3092 if (G_ALERTDEFAULT == val) {
3093 ok = compose_queue(compose, tmp);
3095 alertpanel_error(_("Can't queue the message."));
3098 alertpanel_error_log(_("Error occurred while sending the message."));
3100 if (compose->mode == COMPOSE_REEDIT) {
3101 compose_remove_reedit_target(compose);
3103 /* save message to outbox */
3104 if (prefs_common.savemsg) {
3107 outbox = account_get_special_folder
3108 (compose->account, F_OUTBOX);
3109 if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
3111 (_("Can't save the message to Sent."));
3121 static gboolean compose_use_attach(Compose *compose)
3123 return gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL;
3126 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
3129 gchar buf[BUFFSIZE];
3131 gboolean first_address;
3133 ComposeHeaderEntry *headerentry;
3134 gchar *headerentryname;
3138 debug_print("Writing redirect header\n");
3140 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
3141 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
3143 first_address = TRUE;
3144 for (list = compose->header_list; list; list = list->next) {
3145 headerentry = ((ComposeHeaderEntry *)list->data);
3146 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
3148 if (g_strcasecmp(headerentryname, cc_hdr) == 0
3149 || g_strcasecmp(headerentryname, to_hdr) == 0) {
3150 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
3151 Xstrdup_a(str, str, return -1);
3153 if (str[0] != '\0') {
3154 compose_convert_header
3155 (buf, sizeof(buf), str,
3156 strlen("Resent-To") + 2, TRUE);
3157 if (first_address) {
3158 fprintf(fp, "Resent-To: ");
3159 first_address = FALSE;
3163 fprintf(fp, "%s", buf);
3167 /* if (!first_address) { */
3174 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3176 gchar buf[BUFFSIZE];
3178 /* struct utsname utsbuf; */
3180 g_return_val_if_fail(fp != NULL, -1);
3181 g_return_val_if_fail(compose->account != NULL, -1);
3182 g_return_val_if_fail(compose->account->address != NULL, -1);
3185 get_rfc822_date(buf, sizeof(buf));
3186 fprintf(fp, "Resent-Date: %s\n", buf);
3189 if (compose->account->name && *compose->account->name) {
3190 compose_convert_header
3191 (buf, sizeof(buf), compose->account->name,
3192 strlen("From: "), TRUE);
3193 fprintf(fp, "Resent-From: %s <%s>\n",
3194 buf, compose->account->address);
3196 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3199 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3201 Xstrdup_a(str, str, return -1);
3204 compose_convert_header(buf, sizeof(buf), str,
3205 strlen("Subject: "), FALSE);
3206 fprintf(fp, "Subject: %s\n", buf);
3210 /* Resent-Message-ID */
3211 if (compose->account->gen_msgid) {
3212 compose_generate_msgid(compose, buf, sizeof(buf));
3213 fprintf(fp, "Resent-Message-Id: <%s>\n", buf);
3214 compose->msgid = g_strdup(buf);
3217 compose_redirect_write_headers_from_headerlist(compose, fp);
3219 /* separator between header and body */
3225 static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
3230 gchar buf[BUFFSIZE];
3232 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
3233 FILE_OP_ERROR(file, "fopen");
3237 if ((fdest = fopen(file, "wb")) == NULL) {
3238 FILE_OP_ERROR(file, "fopen");
3243 /* chmod for security */
3244 if (change_file_mode_rw(fdest, file) < 0) {
3245 FILE_OP_ERROR(file, "chmod");
3246 g_warning("can't change file mode\n");
3249 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
3250 /* should filter returnpath, delivered-to */
3251 if (g_strncasecmp(buf, "Return-Path:",
3252 strlen("Return-Path:")) == 0 ||
3253 g_strncasecmp(buf, "Delivered-To:",
3254 strlen("Delivered-To:")) == 0 ||
3255 g_strncasecmp(buf, "Received:",
3256 strlen("Received:")) == 0 ||
3257 g_strncasecmp(buf, "Subject:",
3258 strlen("Subject:")) == 0 ||
3259 g_strncasecmp(buf, "X-UIDL:",
3260 strlen("X-UIDL:")) == 0)
3263 if (fputs(buf, fdest) == -1)
3266 if (!prefs_common.redirect_keep_from) {
3267 if (g_strncasecmp(buf, "From:",
3268 strlen("From:")) == 0) {
3269 fputs(" (by way of ", fdest);
3270 if (compose->account->name
3271 && *compose->account->name) {
3272 compose_convert_header
3274 compose->account->name,
3277 fprintf(fdest, "%s <%s>",
3279 compose->account->address);
3281 fprintf(fdest, "%s",
3282 compose->account->address);
3287 if (fputs("\n", fdest) == -1)
3291 compose_redirect_write_headers(compose, fdest);
3293 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3294 if (fwrite(buf, sizeof(gchar), len, fdest) != len) {
3295 FILE_OP_ERROR(file, "fwrite");
3301 if (fclose(fdest) == EOF) {
3302 FILE_OP_ERROR(file, "fclose");
3318 /* interfaces to rfc2015 to keep out the prefs stuff there.
3319 * returns 0 on success and -1 on error. */
3320 static gint compose_create_signers_list(Compose *compose, GSList **pkey_list)
3322 const gchar *key_id = NULL;
3325 switch (compose->account->sign_key) {
3326 case SIGN_KEY_DEFAULT:
3329 case SIGN_KEY_BY_FROM:
3330 key_id = compose->account->address;
3332 case SIGN_KEY_CUSTOM:
3333 key_id = compose->account->sign_key_id;
3339 key_list = rfc2015_create_signers_list(key_id);
3342 alertpanel_error(_("Could not find any key associated with "
3343 "currently selected key id `%s'."), key_id);
3347 *pkey_list = key_list;
3351 /* clearsign message body text */
3352 static gint compose_clearsign_text(Compose *compose, gchar **text)
3357 tmp_file = get_tmp_file();
3358 if (str_write_to_file(*text, tmp_file) < 0) {
3363 if (compose_create_signers_list(compose, &key_list) < 0 ||
3364 rfc2015_clearsign(tmp_file, key_list) < 0) {
3371 *text = file_read_to_str(tmp_file);
3379 #endif /* USE_GPGME */
3381 static gint compose_write_to_file(Compose *compose, const gchar *file,
3389 const gchar *out_codeset;
3390 EncodingType encoding;
3392 if ((fp = fopen(file, "wb")) == NULL) {
3393 FILE_OP_ERROR(file, "fopen");
3397 /* chmod for security */
3398 if (change_file_mode_rw(fp, file) < 0) {
3399 FILE_OP_ERROR(file, "chmod");
3400 g_warning("can't change file mode\n");
3403 /* get all composed text */
3404 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3405 len = strlen(chars);
3406 if (is_ascii_str(chars)) {
3409 out_codeset = CS_US_ASCII;
3410 encoding = ENC_7BIT;
3412 const gchar *src_codeset;
3414 out_codeset = conv_get_outgoing_charset_str();
3415 if (!strcasecmp(out_codeset, CS_US_ASCII))
3416 out_codeset = CS_ISO_8859_1;
3418 if (prefs_common.encoding_method == CTE_BASE64)
3419 encoding = ENC_BASE64;
3420 else if (prefs_common.encoding_method == CTE_QUOTED_PRINTABLE)
3421 encoding = ENC_QUOTED_PRINTABLE;
3422 else if (prefs_common.encoding_method == CTE_8BIT)
3423 encoding = ENC_8BIT;
3425 encoding = procmime_get_encoding_for_charset(out_codeset);
3429 compose->use_signing && !compose->gnupg_mode &&
3430 encoding == ENC_8BIT)
3431 encoding = ENC_BASE64;
3434 src_codeset = conv_get_current_charset_str();
3435 /* if current encoding is US-ASCII, set it the same as
3436 outgoing one to prevent code conversion failure */
3437 if (!strcasecmp(src_codeset, CS_US_ASCII))
3438 src_codeset = out_codeset;
3440 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3441 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3443 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3448 msg = g_strdup_printf(_("Can't convert the character encoding of the message from\n"
3450 "Send it anyway?"), src_codeset, out_codeset);
3452 (_("Error"), msg, _("Yes"), _("+No"), NULL);
3455 if (aval != G_ALERTDEFAULT) {
3462 out_codeset = src_codeset;
3469 canon_buf = canonicalize_str(buf);
3474 if (!is_draft && compose->use_signing && compose->gnupg_mode) {
3475 if (compose_clearsign_text(compose, &buf) < 0) {
3476 g_warning("clearsign failed\n");
3486 if (compose_write_headers
3487 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3488 g_warning("can't write headers\n");
3495 if (compose_use_attach(compose)) {
3497 /* This prolog message is ignored by mime software and
3498 * because it would make our signing/encryption task
3499 * tougher, we don't emit it in that case */
3500 if (!compose->use_signing && !compose->use_encryption)
3502 fputs("This is a multi-part message in MIME format.\n", fp);
3504 fprintf(fp, "\n--%s\n", compose->boundary);
3505 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3508 if (compose->use_signing && !compose->gnupg_mode)
3509 fprintf(fp, "Content-Disposition: inline\n");
3511 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3512 procmime_get_encoding_str(encoding));
3518 if (encoding == ENC_BASE64) {
3519 gchar outbuf[B64_BUFFSIZE];
3522 for (i = 0; i < len; i += B64_LINE_SIZE) {
3523 l = MIN(B64_LINE_SIZE, len - i);
3524 base64_encode(outbuf, buf + i, l);
3528 } else if (encoding == ENC_QUOTED_PRINTABLE) {
3532 outbuf = g_malloc(len * 4);
3533 qp_encode_line(outbuf, buf);
3534 outlen = strlen(outbuf);
3535 if (fwrite(outbuf, sizeof(gchar), outlen, fp) != outlen) {
3536 FILE_OP_ERROR(file, "fwrite");
3544 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3545 FILE_OP_ERROR(file, "fwrite");
3553 if (compose_use_attach(compose))
3554 compose_write_attach(compose, fp);
3556 if (fclose(fp) == EOF) {
3557 FILE_OP_ERROR(file, "fclose");
3564 uncanonicalize_file_replace(file);
3568 if ((compose->use_signing && !compose->gnupg_mode) ||
3569 compose->use_encryption) {
3570 if (canonicalize_file_replace(file) < 0) {
3576 if (compose->use_signing && !compose->gnupg_mode) {
3579 if (compose_create_signers_list(compose, &key_list) < 0 ||
3580 rfc2015_sign(file, key_list) < 0) {
3585 if (compose->use_encryption) {
3586 if (rfc2015_encrypt(file, compose->to_list,
3587 compose->gnupg_mode) < 0) {
3592 #endif /* USE_GPGME */
3594 uncanonicalize_file_replace(file);
3599 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3605 if ((fp = fopen(file, "wb")) == NULL) {
3606 FILE_OP_ERROR(file, "fopen");
3610 /* chmod for security */
3611 if (change_file_mode_rw(fp, file) < 0) {
3612 FILE_OP_ERROR(file, "chmod");
3613 g_warning("can't change file mode\n");
3616 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3619 len = strlen(chars);
3620 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3621 FILE_OP_ERROR(file, "fwrite");
3630 if (fclose(fp) == EOF) {
3631 FILE_OP_ERROR(file, "fclose");
3638 static gint compose_remove_reedit_target(Compose *compose)
3641 MsgInfo *msginfo = compose->targetinfo;
3643 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3644 if (!msginfo) return -1;
3646 item = msginfo->folder;
3647 g_return_val_if_fail(item != NULL, -1);
3649 if (procmsg_msg_exist(msginfo) &&
3650 (item->stype == F_DRAFT || item->stype == F_QUEUE
3651 || msginfo == compose->autosaved_draft)) {
3652 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3653 g_warning("can't remove the old message\n");
3661 void compose_remove_draft(Compose *compose)
3664 MsgInfo *msginfo = compose->targetinfo;
3665 drafts = account_get_special_folder(compose->account, F_DRAFT);
3667 if (procmsg_msg_exist(msginfo)) {
3668 folder_item_remove_msg(drafts, msginfo->msgnum);
3673 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3675 return compose_queue_sub (compose, msgnum, item, FALSE);
3677 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3683 gchar buf[BUFFSIZE];
3685 static gboolean lock = FALSE;
3686 PrefsAccount *mailac = NULL, *newsac = NULL;
3688 debug_print("queueing message...\n");
3689 g_return_val_if_fail(compose->account != NULL, -1);
3693 if (compose_check_entries(compose, check_subject) == FALSE) {
3698 if (!compose->to_list && !compose->newsgroup_list) {
3699 g_warning("can't get recipient list.");
3704 if (compose->to_list) {
3705 if (compose->account->protocol != A_NNTP)
3706 mailac = compose->account;
3707 else if (cur_account && cur_account->protocol != A_NNTP)
3708 mailac = cur_account;
3709 else if (!(mailac = compose_current_mail_account())) {
3711 alertpanel_error(_("No account for sending mails available!"));
3716 if (compose->newsgroup_list) {
3717 if (compose->account->protocol == A_NNTP)
3718 newsac = compose->account;
3719 else if (!newsac->protocol != A_NNTP) {
3721 alertpanel_error(_("No account for posting news available!"));
3726 if (prefs_common.linewrap_at_send)
3727 compose_wrap_line_all(compose);
3729 /* write to temporary file */
3730 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3731 G_DIR_SEPARATOR, (gint)compose);
3733 if (compose->redirect_filename != NULL) {
3734 if (compose_redirect_write_to_file(compose, tmp2) < 0) {
3741 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3748 /* add queue header */
3749 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),