2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2002 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"
84 #include "customheader.h"
85 #include "prefs_common.h"
86 #include "prefs_account.h"
87 #include "prefs_actions.h"
90 #include "procheader.h"
92 #include "statusbar.h"
99 #include "alertpanel.h"
100 #include "manage_window.h"
101 #include "gtkshruler.h"
103 #include "addr_compl.h"
104 #include "quote_fmt.h"
105 #include "template.h"
107 #include "foldersel.h"
111 # include "rfc2015.h"
121 #define N_ATTACH_COLS 3
125 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
126 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
127 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
128 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
129 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
130 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
131 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
132 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
133 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
134 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
135 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
136 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
137 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
138 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
139 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END
140 } ComposeCallGtkSTextAction;
144 PRIORITY_HIGHEST = 1,
151 #define B64_LINE_SIZE 57
152 #define B64_BUFFSIZE 77
154 #define MAX_REFERENCES_LEN 999
156 static GdkColor quote_color = {0, 0, 0, 0xbfff};
158 static GList *compose_list = NULL;
160 Compose *compose_generic_new (PrefsAccount *account,
163 GPtrArray *attach_files);
165 static Compose *compose_create (PrefsAccount *account,
167 static void compose_toolbar_create (Compose *compose,
168 GtkWidget *container);
169 static void compose_toolbar_update (Compose *compose);
170 static void compose_toolbar_set_sensitive (Compose *compose,
173 static GtkWidget *compose_account_option_menu_create
175 static void compose_set_template_menu (Compose *compose);
176 static void compose_template_apply (Compose *compose,
179 static void compose_destroy (Compose *compose);
181 static void compose_entries_set (Compose *compose,
182 const gchar *mailto);
183 static gint compose_parse_header (Compose *compose,
185 static gchar *compose_parse_references (const gchar *ref,
188 static gchar *compose_quote_fmt (Compose *compose,
194 static void compose_reply_set_entry (Compose *compose,
200 followup_and_reply_to);
201 static void compose_reedit_set_entry (Compose *compose,
203 static void compose_insert_sig (Compose *compose);
204 static void compose_insert_file (Compose *compose,
206 static void compose_attach_append (Compose *compose,
209 const gchar *content_type);
210 static void compose_attach_parts (Compose *compose,
212 static void compose_wrap_line (Compose *compose);
213 static void compose_wrap_line_all (Compose *compose);
214 static void compose_wrap_line_all_full (Compose *compose,
216 static void compose_set_title (Compose *compose);
217 static void compose_select_account (Compose *compose,
218 PrefsAccount *account);
220 static PrefsAccount *compose_current_mail_account(void);
221 /* static gint compose_send (Compose *compose); */
222 static gboolean compose_check_for_valid_recipient
224 static gboolean compose_check_entries (Compose *compose,
225 gboolean check_subject);
226 static gint compose_write_to_file (Compose *compose,
229 static gint compose_write_body_to_file (Compose *compose,
231 static gint compose_remove_reedit_target (Compose *compose);
232 void compose_remove_draft (Compose *compose);
233 static gint compose_queue (Compose *compose,
236 static gint compose_queue_sub (Compose *compose,
239 gboolean check_subject);
240 static void compose_write_attach (Compose *compose,
242 static gint compose_write_headers (Compose *compose,
244 const gchar *charset,
245 EncodingType encoding,
248 static void compose_convert_header (gchar *dest,
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);
300 static void toolbar_send_cb (GtkWidget *widget,
302 static void toolbar_send_later_cb (GtkWidget *widget,
304 static void toolbar_draft_cb (GtkWidget *widget,
306 static void toolbar_insert_cb (GtkWidget *widget,
308 static void toolbar_attach_cb (GtkWidget *widget,
310 static void toolbar_sig_cb (GtkWidget *widget,
312 static void toolbar_ext_editor_cb (GtkWidget *widget,
314 static void toolbar_linewrap_cb (GtkWidget *widget,
316 static void toolbar_address_cb (GtkWidget *widget,
318 static void toolbar_actions_execute_cb (GtkWidget *widget,
320 static void toolbar_compose_buttons_cb (GtkWidget *widget,
322 ToolbarItem *t_item);
323 static void account_activated (GtkMenuItem *menuitem,
326 static void attach_selected (GtkCList *clist,
331 static void attach_button_pressed (GtkWidget *widget,
332 GdkEventButton *event,
334 static void attach_key_pressed (GtkWidget *widget,
338 static void compose_send_cb (gpointer data,
341 static void compose_send_later_cb (gpointer data,
345 static void compose_draft_cb (gpointer data,
349 static void compose_attach_cb (gpointer data,
352 static void compose_insert_file_cb (gpointer data,
356 static void compose_close_cb (gpointer data,
360 static void compose_address_cb (gpointer data,
363 static void compose_template_activate_cb(GtkWidget *widget,
366 static void compose_ext_editor_cb (gpointer data,
370 static gint compose_delete_cb (GtkWidget *widget,
373 static void compose_destroy_cb (GtkWidget *widget,
376 static void compose_undo_cb (Compose *compose);
377 static void compose_redo_cb (Compose *compose);
378 static void compose_cut_cb (Compose *compose);
379 static void compose_copy_cb (Compose *compose);
380 static void compose_paste_cb (Compose *compose);
381 static void compose_paste_as_quote_cb (Compose *compose);
382 static void compose_allsel_cb (Compose *compose);
384 static void compose_gtk_stext_action_cb (Compose *compose,
385 ComposeCallGtkSTextAction action);
387 static void compose_grab_focus_cb (GtkWidget *widget,
390 static void compose_changed_cb (GtkEditable *editable,
392 static void compose_button_press_cb (GtkWidget *widget,
393 GdkEventButton *event,
396 static void compose_key_press_cb (GtkWidget *widget,
402 static void compose_toggle_to_cb (gpointer data,
405 static void compose_toggle_cc_cb (gpointer data,
408 static void compose_toggle_bcc_cb (gpointer data,
411 static void compose_toggle_replyto_cb (gpointer data,
414 static void compose_toggle_followupto_cb(gpointer data,
417 static void compose_toggle_attach_cb (gpointer data,
421 static void compose_toggle_ruler_cb (gpointer data,
425 static void compose_toggle_sign_cb (gpointer data,
428 static void compose_toggle_encrypt_cb (gpointer data,
432 static void compose_toggle_return_receipt_cb(gpointer data, guint action,
434 static void compose_set_priority_cb (gpointer data,
438 static void compose_attach_drag_received_cb (GtkWidget *widget,
439 GdkDragContext *drag_context,
442 GtkSelectionData *data,
446 static void compose_insert_drag_received_cb (GtkWidget *widget,
447 GdkDragContext *drag_context,
450 GtkSelectionData *data,
456 static void to_activated (GtkWidget *widget,
458 static void newsgroups_activated (GtkWidget *widget,
460 static void cc_activated (GtkWidget *widget,
462 static void bcc_activated (GtkWidget *widget,
464 static void replyto_activated (GtkWidget *widget,
466 static void followupto_activated (GtkWidget *widget,
468 static void subject_activated (GtkWidget *widget,
472 static void text_activated (GtkWidget *widget,
474 static void text_inserted (GtkWidget *widget,
479 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
480 gboolean to_all, gboolean to_ml,
481 gboolean ignore_replyto,
482 gboolean followup_and_reply_to,
485 void compose_headerentry_changed_cb (GtkWidget *entry,
486 ComposeHeaderEntry *headerentry);
487 void compose_headerentry_key_press_event_cb(GtkWidget *entry,
489 ComposeHeaderEntry *headerentry);
491 static void compose_show_first_last_header (Compose *compose, gboolean show_first);
494 static void compose_check_all (Compose *compose);
495 static void compose_highlight_all (Compose *compose);
496 static void compose_check_backwards (Compose *compose);
497 static void compose_check_forwards_go (Compose *compose);
500 static gboolean compose_send_control_enter (Compose *compose);
502 static GtkItemFactoryEntry compose_popup_entries[] =
504 {N_("/_Add..."), NULL, compose_attach_cb, 0, NULL},
505 {N_("/_Remove"), NULL, compose_attach_remove_selected, 0, NULL},
506 {N_("/---"), NULL, NULL, 0, "<Separator>"},
507 {N_("/_Property..."), NULL, compose_attach_property, 0, NULL}
510 static GtkItemFactoryEntry compose_entries[] =
512 {N_("/_File"), NULL, NULL, 0, "<Branch>"},
513 {N_("/_File/_Attach file"), "<control>M", compose_attach_cb, 0, NULL},
514 {N_("/_File/_Insert file"), "<control>I", compose_insert_file_cb, 0, NULL},
515 {N_("/_File/Insert si_gnature"), "<control>G", compose_insert_sig, 0, NULL},
516 {N_("/_File/---"), NULL, NULL, 0, "<Separator>"},
517 {N_("/_File/_Close"), "<control>W", compose_close_cb, 0, NULL},
519 {N_("/_Edit"), NULL, NULL, 0, "<Branch>"},
520 {N_("/_Edit/_Undo"), "<control>Z", compose_undo_cb, 0, NULL},
521 {N_("/_Edit/_Redo"), "<control>Y", compose_redo_cb, 0, NULL},
522 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
523 {N_("/_Edit/Cu_t"), "<control>X", compose_cut_cb, 0, NULL},
524 {N_("/_Edit/_Copy"), "<control>C", compose_copy_cb, 0, NULL},
525 {N_("/_Edit/_Paste"), "<control>V", compose_paste_cb, 0, NULL},
526 {N_("/_Edit/Paste as _quotation"),
527 NULL, compose_paste_as_quote_cb, 0, NULL},
528 {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
529 {N_("/_Edit/A_dvanced"), NULL, NULL, 0, "<Branch>"},
530 {N_("/_Edit/A_dvanced/Move a character backward"),
532 compose_gtk_stext_action_cb,
533 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_CHARACTER,
535 {N_("/_Edit/A_dvanced/Move a character forward"),
537 compose_gtk_stext_action_cb,
538 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_CHARACTER,
540 {N_("/_Edit/A_dvanced/Move a word backward"),
542 compose_gtk_stext_action_cb,
543 COMPOSE_CALL_GTK_STEXT_MOVE_BACKWARD_WORD,
545 {N_("/_Edit/A_dvanced/Move a word forward"),
547 compose_gtk_stext_action_cb,
548 COMPOSE_CALL_GTK_STEXT_MOVE_FORWARD_WORD,
550 {N_("/_Edit/A_dvanced/Move to beginning of line"),
551 NULL, /* "<control>A" */
552 compose_gtk_stext_action_cb,
553 COMPOSE_CALL_GTK_STEXT_MOVE_BEGINNING_OF_LINE,
555 {N_("/_Edit/A_dvanced/Move to end of line"),
557 compose_gtk_stext_action_cb,
558 COMPOSE_CALL_GTK_STEXT_MOVE_END_OF_LINE,
560 {N_("/_Edit/A_dvanced/Move to previous line"),
562 compose_gtk_stext_action_cb,
563 COMPOSE_CALL_GTK_STEXT_MOVE_PREVIOUS_LINE,
565 {N_("/_Edit/A_dvanced/Move to next line"),
567 compose_gtk_stext_action_cb,
568 COMPOSE_CALL_GTK_STEXT_MOVE_NEXT_LINE,
570 {N_("/_Edit/A_dvanced/Delete a character backward"),
572 compose_gtk_stext_action_cb,
573 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_CHARACTER,
575 {N_("/_Edit/A_dvanced/Delete a character forward"),
577 compose_gtk_stext_action_cb,
578 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_CHARACTER,
580 {N_("/_Edit/A_dvanced/Delete a word backward"),
581 NULL, /* "<control>W" */
582 compose_gtk_stext_action_cb,
583 COMPOSE_CALL_GTK_STEXT_DELETE_BACKWARD_WORD,
585 {N_("/_Edit/A_dvanced/Delete a word forward"),
586 NULL, /* "<alt>D", */
587 compose_gtk_stext_action_cb,
588 COMPOSE_CALL_GTK_STEXT_DELETE_FORWARD_WORD,
590 {N_("/_Edit/A_dvanced/Delete line"),
592 compose_gtk_stext_action_cb,
593 COMPOSE_CALL_GTK_STEXT_DELETE_LINE,
595 {N_("/_Edit/A_dvanced/Delete entire line"),
597 compose_gtk_stext_action_cb,
598 COMPOSE_CALL_GTK_STEXT_DELETE_LINE_N,
600 {N_("/_Edit/A_dvanced/Delete to end of line"),
602 compose_gtk_stext_action_cb,
603 COMPOSE_CALL_GTK_STEXT_DELETE_TO_LINE_END,
605 {N_("/_Edit/---"), NULL, NULL, 0, "<Separator>"},
606 {N_("/_Edit/_Wrap current paragraph"),
607 "<control>L", compose_wrap_line, 0, NULL},
608 {N_("/_Edit/Wrap all long _lines"),
609 "<control><alt>L", compose_wrap_line_all, 0, NULL},
610 {N_("/_Edit/Edit with e_xternal editor"),
611 "<shift><control>X", compose_ext_editor_cb, 0, NULL},
613 {N_("/_Spelling"), NULL, NULL, 0, "<Branch>"},
614 {N_("/_Spelling/_Check all or check selection"),
615 NULL, compose_check_all, 0, NULL},
616 {N_("/_Spelling/_Highlight all misspelled words"),
617 NULL, compose_highlight_all, 0, NULL},
618 {N_("/_Spelling/Check _backwards misspelled word"),
619 NULL, compose_check_backwards , 0, NULL},
620 {N_("/_Spelling/_Forward to next misspelled word"),
621 NULL, compose_check_forwards_go, 0, NULL},
622 {N_("/_Spelling/---"), NULL, NULL, 0, "<Separator>"},
623 {N_("/_Spelling/_Spelling Configuration"),
624 NULL, NULL, 0, "<Branch>"},
626 #if 0 /* NEW COMPOSE GUI */
627 {N_("/_View"), NULL, NULL, 0, "<Branch>"},
628 {N_("/_View/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
629 {N_("/_View/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
630 {N_("/_View/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
631 {N_("/_View/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
632 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
633 {N_("/_View/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
634 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
635 {N_("/_View/R_uler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
636 {N_("/_View/---"), NULL, NULL, 0, "<Separator>"},
637 {N_("/_View/_Attachment"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
639 {N_("/_Message"), NULL, NULL, 0, "<Branch>"},
640 {N_("/_Message/_Send"), "<control>Return",
641 compose_send_cb, 0, NULL},
642 {N_("/_Message/Send _later"), "<shift><control>S",
643 compose_send_later_cb, 0, NULL},
644 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
645 {N_("/_Message/Save to _draft folder"),
646 "<shift><control>D", compose_draft_cb, 0, NULL},
647 {N_("/_Message/Save and _keep editing"),
648 "<control>S", compose_draft_cb, 1, NULL},
649 #if 0 /* NEW COMPOSE GUI */
650 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
651 {N_("/_Message/_To"), NULL, compose_toggle_to_cb , 0, "<ToggleItem>"},
652 {N_("/_Message/_Cc"), NULL, compose_toggle_cc_cb , 0, "<ToggleItem>"},
653 {N_("/_Message/_Bcc"), NULL, compose_toggle_bcc_cb , 0, "<ToggleItem>"},
654 {N_("/_Message/_Reply to"), NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
655 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
656 {N_("/_Message/_Followup to"), NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
657 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
658 {N_("/_Message/_Attach"), NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
661 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
662 {N_("/_Message/Si_gn"), NULL, compose_toggle_sign_cb , 0, "<ToggleItem>"},
663 {N_("/_Message/_Encrypt"), NULL, compose_toggle_encrypt_cb, 0, "<ToggleItem>"},
664 #endif /* USE_GPGME */
665 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
666 {N_("/_Message/_Priority"), NULL, NULL, 0, "<Branch>"},
667 {N_("/_Message/Priority/_Highest"), NULL, compose_set_priority_cb, PRIORITY_HIGHEST, "<RadioItem>"},
668 {N_("/_Message/Priority/Hi_gh"), NULL, compose_set_priority_cb, PRIORITY_HIGH, "/Message/Priority/Highest"},
669 {N_("/_Message/Priority/_Normal"), NULL, compose_set_priority_cb, PRIORITY_NORMAL, "/Message/Priority/Highest"},
670 {N_("/_Message/Priority/Lo_w"), NULL, compose_set_priority_cb, PRIORITY_LOW, "/Message/Priority/Highest"},
671 {N_("/_Message/Priority/_Lowest"), NULL, compose_set_priority_cb, PRIORITY_LOWEST, "/Message/Priority/Highest"},
672 {N_("/_Message/---"), NULL, NULL, 0, "<Separator>"},
673 {N_("/_Message/_Request Return Receipt"), NULL, compose_toggle_return_receipt_cb, 0, "<ToggleItem>"},
674 {N_("/_Tools"), NULL, NULL, 0, "<Branch>"},
675 {N_("/_Tools/Show _ruler"), NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
676 {N_("/_Tools/_Address book"), "<shift><control>A", compose_address_cb , 0, NULL},
677 {N_("/_Tools/_Template"), NULL, NULL, 0, "<Branch>"},
678 {N_("/_Tools/Actio_ns"), NULL, NULL, 0, "<Branch>"},
679 {N_("/_Help"), NULL, NULL, 0, "<Branch>"},
680 {N_("/_Help/_About"), NULL, about_show, 0, NULL}
683 static GtkTargetEntry compose_mime_types[] =
685 {"text/uri-list", 0, 0}
688 Compose *compose_new(PrefsAccount *account, const gchar *mailto,
689 GPtrArray *attach_files)
691 return compose_generic_new(account, mailto, NULL, attach_files);
694 Compose *compose_new_with_folderitem(PrefsAccount *account, FolderItem *item)
696 return compose_generic_new(account, NULL, item, NULL);
699 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
700 GPtrArray *attach_files)
704 GtkItemFactory *ifactory;
705 gboolean grab_focus_on_last = TRUE;
707 if (item && item->prefs && item->prefs->enable_default_account)
708 account = account_find_from_id(item->prefs->default_account);
710 if (!account) account = cur_account;
711 g_return_val_if_fail(account != NULL, NULL);
713 compose = compose_create(account, COMPOSE_NEW);
714 ifactory = gtk_item_factory_from_widget(compose->menubar);
716 compose->replyinfo = NULL;
718 text = GTK_STEXT(compose->text);
719 gtk_stext_freeze(text);
721 if (prefs_common.auto_sig)
722 compose_insert_sig(compose);
723 gtk_editable_set_position(GTK_EDITABLE(text), 0);
724 gtk_stext_set_point(text, 0);
726 gtk_stext_thaw(text);
728 /* workaround for initial XIM problem */
729 gtk_widget_grab_focus(compose->text);
730 gtkut_widget_wait_for_draw(compose->text);
732 if (account->protocol != A_NNTP) {
733 if (mailto && *mailto != '\0') {
734 compose_entries_set(compose, mailto);
736 } else if (item && item->prefs->enable_default_to) {
737 compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
738 compose_entry_select(compose, item->prefs->default_to);
739 grab_focus_on_last = FALSE;
741 if (item && item->ret_rcpt) {
742 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
746 compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
749 * CLAWS: just don't allow return receipt request, even if the user
750 * may want to send an email. simple but foolproof.
752 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
759 for (i = 0; i < attach_files->len; i++) {
760 file = g_ptr_array_index(attach_files, i);
761 compose_attach_append(compose, file, file, NULL);
765 compose_show_first_last_header(compose, TRUE);
767 /* Set save folder */
768 if (item && item->prefs && item->prefs->save_copy_to_folder) {
769 gchar *folderidentifier;
771 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
772 folderidentifier = folder_item_get_identifier(item);
773 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
774 g_free(folderidentifier);
777 /* Grab focus on last header only if no default_to was set */
778 if (grab_focus_on_last)
779 gtk_widget_grab_focus(compose->header_last->entry);
781 if (prefs_common.auto_exteditor)
782 compose_exec_ext_editor(compose);
787 #define CHANGE_FLAGS(msginfo) \
789 if (msginfo->folder->folder->change_flags != NULL) \
790 msginfo->folder->folder->change_flags(msginfo->folder->folder, \
796 Compose *compose_new_followup_and_replyto(PrefsAccount *account,
797 const gchar *followupto, gchar * to)
801 if (!account) account = cur_account;
802 g_return_val_if_fail(account != NULL, NULL);
803 g_return_val_if_fail(account->protocol != A_NNTP, NULL);
805 compose = compose_create(account, COMPOSE_NEW);
807 if (prefs_common.auto_sig)
808 compose_insert_sig(compose);
809 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
810 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
812 compose_entry_append(compose, to, COMPOSE_TO);
813 compose_entry_append(compose, followupto, COMPOSE_NEWSGROUPS);
814 gtk_widget_grab_focus(compose->subject_entry);
820 void compose_reply(MsgInfo *msginfo, gboolean quote, gboolean to_all,
821 gboolean to_ml, gboolean ignore_replyto,
824 compose_generic_reply(msginfo, quote, to_all, to_ml,
825 ignore_replyto, FALSE, body);
828 void compose_followup_and_reply_to(MsgInfo *msginfo, gboolean quote,
830 gboolean ignore_replyto,
833 compose_generic_reply(msginfo, quote, to_all, FALSE,
834 ignore_replyto, TRUE, body);
837 static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
838 gboolean to_all, gboolean to_ml,
839 gboolean ignore_replyto,
840 gboolean followup_and_reply_to,
844 PrefsAccount *account;
845 PrefsAccount *reply_account;
848 g_return_if_fail(msginfo != NULL);
849 g_return_if_fail(msginfo->folder != NULL);
852 /* select the account set in folderitem's property (if enabled) */
853 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
854 account = account_find_from_id(msginfo->folder->prefs->default_account);
856 /* select the account for the whole folder (IMAP / NNTP) */
858 /* FIXME: this is not right, because folder may be nested. we should
859 * ascend the tree until we find a parent with proper account
861 account = msginfo->folder->folder->account;
863 /* select account by to: and cc: header if enabled */
864 if (prefs_common.reply_account_autosel) {
865 if (!account && msginfo->to) {
867 Xstrdup_a(to, msginfo->to, return);
869 account = account_find_from_address(to);
873 if (!get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
875 account = account_find_from_address(cc);
880 /* select current account */
881 if (!account) account = cur_account;
882 g_return_if_fail(account != NULL);
884 if (ignore_replyto && account->protocol == A_NNTP &&
885 !followup_and_reply_to) {
887 account_find_from_address(account->address);
889 reply_account = compose_current_mail_account();
893 reply_account = account;
895 compose = compose_create(account, COMPOSE_REPLY);
896 compose->replyinfo = procmsg_msginfo_new_ref(msginfo);
898 #if 0 /* NEW COMPOSE GUI */
899 if (followup_and_reply_to) {
900 gtk_widget_show(compose->to_hbox);
901 gtk_widget_show(compose->to_entry);
902 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 1, 4);
903 compose->use_to = TRUE;
906 if (msginfo->folder && msginfo->folder->ret_rcpt) {
907 GtkItemFactory *ifactory;
909 ifactory = gtk_item_factory_from_widget(compose->menubar);
910 menu_set_toggle(ifactory, "/Message/Request Return Receipt", TRUE);
913 /* Set save folder */
914 if (msginfo->folder && msginfo->folder->prefs && msginfo->folder->prefs->save_copy_to_folder) {
915 gchar *folderidentifier;
917 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
918 folderidentifier = folder_item_get_identifier(msginfo->folder);
919 gtk_entry_set_text(GTK_ENTRY(compose->savemsg_entry), folderidentifier);
920 g_free(folderidentifier);
923 if (compose_parse_header(compose, msginfo) < 0) return;
924 compose_reply_set_entry(compose, msginfo, to_all, to_ml,
925 ignore_replyto, followup_and_reply_to);
926 compose_show_first_last_header(compose, TRUE);
928 text = GTK_STEXT(compose->text);
929 gtk_stext_freeze(text);
935 if (prefs_common.quotemark && *prefs_common.quotemark)
936 qmark = prefs_common.quotemark;
940 quote_str = compose_quote_fmt(compose, msginfo,
941 prefs_common.quotefmt,
945 if (prefs_common.auto_sig)
946 compose_insert_sig(compose);
948 if (quote && prefs_common.linewrap_quote)
949 compose_wrap_line_all(compose);
951 gtk_editable_set_position(GTK_EDITABLE(text), 0);
952 gtk_stext_set_point(text, 0);
954 gtk_stext_thaw(text);
955 gtk_widget_grab_focus(compose->text);
957 if (prefs_common.auto_exteditor)
958 compose_exec_ext_editor(compose);
961 static void set_toolbar_style(Compose *compose);
963 #define INSERT_FW_HEADER(var, hdr) \
964 if (msginfo->var && *msginfo->var) { \
965 gtk_stext_insert(text, NULL, NULL, NULL, hdr, -1); \
966 gtk_stext_insert(text, NULL, NULL, NULL, msginfo->var, -1); \
967 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1); \
970 Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
971 gboolean as_attach, const gchar *body)
974 /* PrefsAccount *account; */
977 g_return_val_if_fail(msginfo != NULL, NULL);
978 g_return_val_if_fail(msginfo->folder != NULL, NULL);
980 account = msginfo->folder->folder->account;
981 if (!account && msginfo->to && prefs_common.forward_account_autosel) {
983 Xstrdup_a(to, msginfo->to, return NULL);
985 account = account_find_from_address(to);
988 if (!account && prefs_common.forward_account_autosel) {
990 if (!get_header_from_msginfo(msginfo,cc,sizeof(cc),"CC:")){ /* Found a CC header */
992 account = account_find_from_address(cc);
996 if (account == NULL) {
997 account = cur_account;
999 account = msginfo->folder->folder->account;
1000 if (!account) account = cur_account;
1003 g_return_val_if_fail(account != NULL, NULL);
1005 MSG_UNSET_PERM_FLAGS(msginfo->flags, MSG_REPLIED);
1006 MSG_SET_PERM_FLAGS(msginfo->flags, MSG_FORWARDED);
1007 if (MSG_IS_IMAP(msginfo->flags))
1008 imap_msg_unset_perm_flags(msginfo, MSG_REPLIED);
1009 CHANGE_FLAGS(msginfo);
1011 compose = compose_create(account, COMPOSE_FORWARD);
1013 if (msginfo->subject && *msginfo->subject) {
1014 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Fw: ");
1015 gtk_entry_append_text(GTK_ENTRY(compose->subject_entry),
1019 text = GTK_STEXT(compose->text);
1020 gtk_stext_freeze(text);
1026 msgfile = procmsg_get_message_file_path(msginfo);
1027 if (!is_file_exist(msgfile))
1028 g_warning(_("%s: file not exist\n"), msgfile);
1030 compose_attach_append(compose, msgfile, msgfile,
1038 if (prefs_common.fw_quotemark &&
1039 *prefs_common.fw_quotemark)
1040 qmark = prefs_common.fw_quotemark;
1044 quote_str = compose_quote_fmt(compose, msginfo,
1045 prefs_common.fw_quotefmt,
1047 compose_attach_parts(compose, msginfo);
1050 if (prefs_common.auto_sig)
1051 compose_insert_sig(compose);
1053 if (prefs_common.linewrap_quote)
1054 compose_wrap_line_all(compose);
1056 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1057 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1059 gtk_stext_thaw(text);
1060 #if 0 /* NEW COMPOSE GUI */
1061 if (account->protocol != A_NNTP)
1062 gtk_widget_grab_focus(compose->to_entry);
1064 gtk_widget_grab_focus(compose->newsgroups_entry);
1066 gtk_widget_grab_focus(compose->header_last->entry);
1068 if (prefs_common.auto_exteditor)
1069 compose_exec_ext_editor(compose);
1074 #undef INSERT_FW_HEADER
1076 Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
1083 g_return_val_if_fail(msginfo_list != NULL, NULL);
1085 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1086 if ( ((MsgInfo *)msginfo->data)->folder == NULL )
1090 if (account == NULL) {
1091 account = cur_account;
1093 account = msginfo->folder->folder->account;
1094 if (!account) account = cur_account;
1097 g_return_val_if_fail(account != NULL, NULL);
1099 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1100 MSG_UNSET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_REPLIED);
1101 MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
1102 CHANGE_FLAGS(((MsgInfo *)msginfo->data));
1105 compose = compose_create(account, COMPOSE_FORWARD);
1107 text = GTK_STEXT(compose->text);
1108 gtk_stext_freeze(text);
1110 for (msginfo = msginfo_list; msginfo != NULL; msginfo = msginfo->next) {
1111 msgfile = procmsg_get_message_file_path((MsgInfo *)msginfo->data);
1112 if (!is_file_exist(msgfile))
1113 g_warning(_("%s: file not exist\n"), msgfile);
1115 compose_attach_append(compose, msgfile, msgfile,
1120 if (prefs_common.auto_sig)
1121 compose_insert_sig(compose);
1123 if (prefs_common.linewrap_quote)
1124 compose_wrap_line_all(compose);
1126 gtk_editable_set_position(GTK_EDITABLE(compose->text), 0);
1127 gtk_stext_set_point(GTK_STEXT(compose->text), 0);
1129 gtk_stext_thaw(text);
1130 gtk_widget_grab_focus(compose->header_last->entry);
1132 #if 0 /* NEW COMPOSE GUI */
1133 if (account->protocol != A_NNTP)
1134 gtk_widget_grab_focus(compose->to_entry);
1136 gtk_widget_grab_focus(compose->newsgroups_entry);
1142 void compose_reedit(MsgInfo *msginfo)
1145 PrefsAccount *account = NULL;
1148 gchar buf[BUFFSIZE];
1150 g_return_if_fail(msginfo != NULL);
1151 g_return_if_fail(msginfo->folder != NULL);
1153 if (msginfo->folder->stype == F_QUEUE) {
1154 gchar queueheader_buf[BUFFSIZE];
1157 /* Select Account from queue headers */
1158 if (!get_header_from_msginfo(msginfo, queueheader_buf,
1159 sizeof(queueheader_buf), "NAID:")) {
1160 id = atoi(&queueheader_buf[5]);
1161 account = account_find_from_id(id);
1163 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1164 sizeof(queueheader_buf), "MAID:")) {
1165 id = atoi(&queueheader_buf[5]);
1166 account = account_find_from_id(id);
1168 if (!account && !get_header_from_msginfo(msginfo, queueheader_buf,
1169 sizeof(queueheader_buf), "S:")) {
1170 account = account_find_from_address(queueheader_buf);
1173 account = msginfo->folder->folder->account;
1175 if (!account && prefs_common.reedit_account_autosel) {
1176 gchar from[BUFFSIZE];
1177 if (!get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")){
1178 extract_address(from);
1179 account = account_find_from_address(from);
1182 if (!account) account = cur_account;
1183 g_return_if_fail(account != NULL);
1185 compose = compose_create(account, COMPOSE_REEDIT);
1186 compose->targetinfo = procmsg_msginfo_copy(msginfo);
1188 if (msginfo->folder->stype == F_QUEUE
1189 || msginfo->folder->stype == F_DRAFT) {
1190 gchar queueheader_buf[BUFFSIZE];
1192 /* Set message save folder */
1193 if (!get_header_from_msginfo(msginfo, queueheader_buf, sizeof(queueheader_buf), "SCF:")) {
1196 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
1197 gtk_editable_delete_text(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
1198 gtk_editable_insert_text(GTK_EDITABLE(compose->savemsg_entry), &queueheader_buf[4], strlen(&queueheader_buf[4]), &startpos);
1202 if (compose_parse_header(compose, msginfo) < 0) return;
1203 compose_reedit_set_entry(compose, msginfo);
1205 text = GTK_STEXT(compose->text);
1206 gtk_stext_freeze(text);
1208 if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
1209 g_warning(_("Can't get text part\n"));
1211 while (fgets(buf, sizeof(buf), fp) != NULL)
1212 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1215 compose_attach_parts(compose, msginfo);
1217 gtk_stext_thaw(text);
1218 gtk_widget_grab_focus(compose->text);
1220 if (prefs_common.auto_exteditor)
1221 compose_exec_ext_editor(compose);
1224 Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
1228 GtkItemFactory *ifactory;
1230 g_return_val_if_fail(msginfo != NULL, NULL);
1233 account = cur_account;
1234 g_return_val_if_fail(account != NULL, NULL);
1236 compose = compose_create(account, COMPOSE_REDIRECT);
1237 ifactory = gtk_item_factory_from_widget(compose->menubar);
1239 compose->replyinfo = NULL;
1241 compose_show_first_last_header(compose, TRUE);
1243 gtk_widget_grab_focus(compose->header_last->entry);
1245 filename = procmsg_get_message_file(msginfo);
1246 if (filename == NULL)
1249 compose->redirect_filename = filename;
1251 if (msginfo->subject)
1252 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
1254 gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
1256 gtk_stext_freeze(GTK_STEXT(compose->text));
1257 compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
1258 gtk_editable_set_editable(GTK_EDITABLE(compose->text), FALSE);
1259 gtk_stext_thaw(GTK_STEXT(compose->text));
1261 ifactory = gtk_item_factory_from_widget(compose->popupmenu);
1262 menu_set_sensitive(ifactory, "/Add...", FALSE);
1263 menu_set_sensitive(ifactory, "/Remove", FALSE);
1264 menu_set_sensitive(ifactory, "/Property...", FALSE);
1266 ifactory = gtk_item_factory_from_widget(compose->menubar);
1267 menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
1268 menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
1269 menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
1270 menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
1271 menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
1272 menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
1273 menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
1274 menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
1276 menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
1277 menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
1279 menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
1280 menu_set_sensitive(ifactory, "/Tools/Template", FALSE);
1282 gtk_widget_set_sensitive(compose->toolbar->insert_btn, FALSE);
1283 gtk_widget_set_sensitive(compose->toolbar->attach_btn, FALSE);
1284 gtk_widget_set_sensitive(compose->toolbar->sig_btn, FALSE);
1285 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, FALSE);
1286 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, FALSE);
1291 GList *compose_get_compose_list(void)
1293 return compose_list;
1296 void compose_entry_append(Compose *compose, const gchar *address,
1297 ComposeEntryType type)
1301 if (!address || *address == '\0') return;
1303 #if 0 /* NEW COMPOSE GUI */
1306 entry = GTK_ENTRY(compose->cc_entry);
1309 entry = GTK_ENTRY(compose->bcc_entry);
1311 case COMPOSE_NEWSGROUPS:
1312 entry = GTK_ENTRY(compose->newsgroups_entry);
1316 entry = GTK_ENTRY(compose->to_entry);
1320 text = gtk_entry_get_text(entry);
1322 gtk_entry_append_text(entry, ", ");
1323 gtk_entry_append_text(entry, address);
1331 header = N_("Bcc:");
1333 case COMPOSE_REPLYTO:
1334 header = N_("Reply-To:");
1336 case COMPOSE_NEWSGROUPS:
1337 header = N_("Newsgroups:");
1339 case COMPOSE_FOLLOWUPTO:
1340 header = N_( "Followup-To:");
1347 header = prefs_common.trans_hdr ? gettext(header) : header;
1349 compose_add_header_entry(compose, header, (gchar *)address);
1352 void compose_entry_select (Compose *compose, const gchar *mailto)
1354 GSList *header_list;
1356 for (header_list = compose->header_list; header_list != NULL; header_list = header_list->next) {
1357 GtkEntry * entry = GTK_ENTRY(((ComposeHeaderEntry *)header_list->data)->entry);
1359 if (gtk_entry_get_text(entry) && !g_strcasecmp(gtk_entry_get_text(entry), mailto)) {
1360 gtk_entry_select_region(entry, 0, -1);
1361 gtk_widget_grab_focus(GTK_WIDGET(entry));
1366 static void compose_entries_set(Compose *compose, const gchar *mailto)
1371 gchar *subject = NULL;
1374 scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
1377 compose_entry_append(compose, to, COMPOSE_TO);
1379 compose_entry_append(compose, cc, COMPOSE_CC);
1381 compose_entry_append(compose, bcc, COMPOSE_BCC);
1383 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
1385 gtk_stext_insert(GTK_STEXT(compose->text),
1386 NULL, NULL, NULL, body, -1);
1387 gtk_stext_insert(GTK_STEXT(compose->text),
1388 NULL, NULL, NULL, "\n", 1);
1398 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
1400 static HeaderEntry hentry[] = {{"Reply-To:", NULL, TRUE},
1401 {"Cc:", NULL, FALSE},
1402 {"References:", NULL, FALSE},
1403 {"Bcc:", NULL, FALSE},
1404 {"Newsgroups:", NULL, FALSE},
1405 {"Followup-To:", NULL, FALSE},
1406 {"List-Post:", NULL, FALSE},
1407 {"X-Priority:", NULL, FALSE},
1408 {NULL, NULL, FALSE}};
1424 g_return_val_if_fail(msginfo != NULL, -1);
1426 if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
1427 procheader_get_header_fields(fp, hentry);
1430 if (hentry[H_REPLY_TO].body != NULL) {
1431 conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
1432 compose->replyto = hentry[H_REPLY_TO].body;
1433 hentry[H_REPLY_TO].body = NULL;
1435 if (hentry[H_CC].body != NULL) {
1436 conv_unmime_header_overwrite(hentry[H_CC].body);
1437 compose->cc = hentry[H_CC].body;
1438 hentry[H_CC].body = NULL;
1440 if (hentry[H_REFERENCES].body != NULL) {
1441 if (compose->mode == COMPOSE_REEDIT)
1442 compose->references = hentry[H_REFERENCES].body;
1444 compose->references = compose_parse_references
1445 (hentry[H_REFERENCES].body, msginfo->msgid);
1446 g_free(hentry[H_REFERENCES].body);
1448 hentry[H_REFERENCES].body = NULL;
1450 if (hentry[H_BCC].body != NULL) {
1451 if (compose->mode == COMPOSE_REEDIT) {
1452 conv_unmime_header_overwrite(hentry[H_BCC].body);
1453 compose->bcc = hentry[H_BCC].body;
1455 g_free(hentry[H_BCC].body);
1456 hentry[H_BCC].body = NULL;
1458 if (hentry[H_NEWSGROUPS].body != NULL) {
1459 compose->newsgroups = hentry[H_NEWSGROUPS].body;
1460 hentry[H_NEWSGROUPS].body = NULL;
1462 if (hentry[H_FOLLOWUP_TO].body != NULL) {
1463 conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
1464 compose->followup_to = hentry[H_FOLLOWUP_TO].body;
1465 hentry[H_FOLLOWUP_TO].body = NULL;
1467 if (hentry[H_LIST_POST].body != NULL) {
1470 extract_address(hentry[H_LIST_POST].body);
1471 if (hentry[H_LIST_POST].body[0] != '\0') {
1472 scan_mailto_url(hentry[H_LIST_POST].body,
1473 &to, NULL, NULL, NULL, NULL);
1475 g_free(compose->ml_post);
1476 compose->ml_post = to;
1479 g_free(hentry[H_LIST_POST].body);
1480 hentry[H_LIST_POST].body = NULL;
1483 if (compose->mode == COMPOSE_REEDIT)
1484 if (hentry[H_X_PRIORITY].body != NULL) {
1487 priority = atoi(hentry[H_X_PRIORITY].body);
1488 g_free(hentry[H_X_PRIORITY].body);
1490 hentry[H_X_PRIORITY].body = NULL;
1492 if (priority < PRIORITY_HIGHEST ||
1493 priority > PRIORITY_LOWEST)
1494 priority = PRIORITY_NORMAL;
1496 compose->priority = priority;
1499 if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
1500 compose->inreplyto = g_strdup(msginfo->inreplyto);
1501 else if (compose->mode != COMPOSE_REEDIT &&
1502 msginfo->msgid && *msginfo->msgid) {
1503 compose->inreplyto = g_strdup(msginfo->msgid);
1505 if (!compose->references) {
1506 if (msginfo->inreplyto && *msginfo->inreplyto)
1507 compose->references =
1508 g_strdup_printf("<%s>\n\t<%s>",
1512 compose->references =
1513 g_strconcat("<", msginfo->msgid, ">",
1521 static gchar *compose_parse_references(const gchar *ref, const gchar *msgid)
1523 GSList *ref_id_list, *cur;
1527 ref_id_list = references_list_append(NULL, ref);
1528 if (!ref_id_list) return NULL;
1529 if (msgid && *msgid)
1530 ref_id_list = g_slist_append(ref_id_list, g_strdup(msgid));
1535 for (cur = ref_id_list; cur != NULL; cur = cur->next)
1536 /* "<" + Message-ID + ">" + CR+LF+TAB */
1537 len += strlen((gchar *)cur->data) + 5;
1539 if (len > MAX_REFERENCES_LEN) {
1540 /* remove second message-ID */
1541 if (ref_id_list && ref_id_list->next &&
1542 ref_id_list->next->next) {
1543 g_free(ref_id_list->next->data);
1544 ref_id_list = g_slist_remove
1545 (ref_id_list, ref_id_list->next->data);
1547 slist_free_strings(ref_id_list);
1548 g_slist_free(ref_id_list);
1555 new_ref = g_string_new("");
1556 for (cur = ref_id_list; cur != NULL; cur = cur->next) {
1557 if (new_ref->len > 0)
1558 g_string_append(new_ref, "\n\t");
1559 g_string_sprintfa(new_ref, "<%s>", (gchar *)cur->data);
1562 slist_free_strings(ref_id_list);
1563 g_slist_free(ref_id_list);
1565 new_ref_str = new_ref->str;
1566 g_string_free(new_ref, FALSE);
1571 static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
1572 const gchar *fmt, const gchar *qmark,
1575 GtkSText *text = GTK_STEXT(compose->text);
1576 static MsgInfo dummyinfo;
1577 gchar *quote_str = NULL;
1583 msginfo = &dummyinfo;
1585 if (qmark != NULL) {
1586 quote_fmt_init(msginfo, NULL, NULL);
1587 quote_fmt_scan_string(qmark);
1590 buf = quote_fmt_get_buffer();
1592 alertpanel_error(_("Quote mark format error."));
1594 Xstrdup_a(quote_str, buf, return NULL)
1597 if (fmt && *fmt != '\0') {
1598 quote_fmt_init(msginfo, quote_str, body);
1599 quote_fmt_scan_string(fmt);
1602 buf = quote_fmt_get_buffer();
1604 alertpanel_error(_("Message reply/forward format error."));
1610 gtk_stext_freeze(text);
1612 for (p = buf; *p != '\0'; ) {
1613 lastp = strchr(p, '\n');
1614 len = lastp ? lastp - p + 1 : -1;
1615 gtk_stext_insert(text, NULL, NULL, NULL, p, len);
1622 gtk_stext_thaw(text);
1627 static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
1628 gboolean to_all, gboolean to_ml,
1629 gboolean ignore_replyto,
1630 gboolean followup_and_reply_to)
1632 GSList *cc_list = NULL;
1635 gchar *replyto = NULL;
1636 GHashTable *to_table;
1638 g_return_if_fail(compose->account != NULL);
1639 g_return_if_fail(msginfo != NULL);
1641 if (to_ml && compose->ml_post) {
1642 compose_entry_append(compose, compose->ml_post,
1644 } else if ((compose->account->protocol != A_NNTP) || followup_and_reply_to) {
1645 compose_entry_append(compose,
1646 ((compose->replyto && !ignore_replyto)
1648 : msginfo->from ? msginfo->from : ""),
1652 compose_entry_append
1653 (compose, msginfo->from ? msginfo->from : "",
1656 if (compose->followup_to && !strncmp(compose->followup_to,"poster",6)) {
1657 compose_entry_append
1659 ((compose->replyto && !ignore_replyto)
1661 : msginfo->from ? msginfo->from : ""),
1664 compose_entry_append
1666 compose->followup_to ? compose->followup_to
1667 : compose->newsgroups ? compose->newsgroups
1669 COMPOSE_NEWSGROUPS);
1674 if (msginfo->subject && *msginfo->subject) {
1675 gchar *buf, *buf2, *p;
1677 buf = g_strdup(msginfo->subject);
1678 while (!strncasecmp(buf, "Re:", 3)) {
1680 while (isspace(*p)) p++;
1681 memmove(buf, p, strlen(p) + 1);
1684 buf2 = g_strdup_printf("Re: %s", buf);
1685 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf2);
1689 gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), "Re: ");
1691 if (to_ml && compose->ml_post) return;
1692 if (!to_all || compose->account->protocol == A_NNTP) return;
1694 if (compose->replyto) {
1695 Xstrdup_a(replyto, compose->replyto, return);
1696 extract_address(replyto);
1698 if (msginfo->from) {
1699 Xstrdup_a(from, msginfo->from, return);
1700 extract_address(from);
1703 if (replyto && from)
1704 cc_list = address_list_append(cc_list, from);
1705 cc_list = address_list_append(cc_list, msginfo->to);
1706 cc_list = address_list_append(cc_list, compose->cc);
1708 to_table = g_hash_table_new(g_str_hash, g_str_equal);
1710 g_hash_table_insert(to_table, replyto, GINT_TO_POINTER(1));
1711 if (compose->account)
1712 g_hash_table_insert(to_table, compose->account->address,
1713 GINT_TO_POINTER(1));
1715 /* remove address on To: and that of current account */
1716 for (cur = cc_list; cur != NULL; ) {
1717 GSList *next = cur->next;
1719 if (g_hash_table_lookup(to_table, cur->data) != NULL)
1720 cc_list = g_slist_remove(cc_list, cur->data);
1722 g_hash_table_insert(to_table, cur->data, cur);
1726 g_hash_table_destroy(to_table);
1729 for (cur = cc_list; cur != NULL; cur = cur->next)
1730 compose_entry_append(compose, (gchar *)cur->data,
1732 slist_free_strings(cc_list);
1733 g_slist_free(cc_list);
1737 #define SET_ENTRY(entry, str) \
1740 gtk_entry_set_text(GTK_ENTRY(compose->entry), str); \
1743 #define SET_ADDRESS(type, str) \
1746 compose_entry_append(compose, str, type); \
1749 static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
1751 g_return_if_fail(msginfo != NULL);
1753 SET_ENTRY(subject_entry, msginfo->subject);
1754 SET_ADDRESS(COMPOSE_TO, msginfo->to);
1755 SET_ADDRESS(COMPOSE_CC, compose->cc);
1756 SET_ADDRESS(COMPOSE_BCC, compose->bcc);
1757 SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
1759 compose_update_priority_menu_item(compose);
1761 compose_show_first_last_header(compose, TRUE);
1763 #if 0 /* NEW COMPOSE GUI */
1765 GtkItemFactory *ifactory;
1766 GtkWidget *menuitem;
1768 ifactory = gtk_item_factory_from_widget(compose->menubar);
1769 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
1770 gtk_check_menu_item_set_active
1771 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1773 if (compose->replyto) {
1774 GtkItemFactory *ifactory;
1775 GtkWidget *menuitem;
1777 ifactory = gtk_item_factory_from_widget(compose->menubar);
1778 menuitem = gtk_item_factory_get_item
1779 (ifactory, "/View/Reply to");
1780 gtk_check_menu_item_set_active
1781 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
1789 static void compose_exec_sig(Compose *compose, gchar *sigfile)
1793 size_t buf_len = 128;
1795 if (strlen(sigfile) < 2)
1798 sigprg = popen(sigfile+1, "r");
1801 buf = g_malloc(buf_len);
1804 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1805 "Unable to insert signature (malloc failed)\n", -1);
1811 while (!feof(sigprg)) {
1812 bzero(buf, buf_len);
1813 fread(buf, buf_len-1, 1, sigprg);
1814 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, buf, -1);
1822 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1823 "Can't exec file: ", -1);
1824 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, \
1829 static void compose_insert_sig(Compose *compose)
1833 if (compose->account && compose->account->sig_path)
1834 sigfile = g_strdup(compose->account->sig_path);
1836 sigfile = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
1837 DEFAULT_SIGNATURE, NULL);
1839 if (!is_file_or_fifo_exist(sigfile) && sigfile[0] != '|') {
1844 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL, "\n\n", 2);
1845 if (prefs_common.sig_sep) {
1846 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1847 prefs_common.sig_sep, -1);
1848 gtk_stext_insert(GTK_STEXT(compose->text), NULL, NULL, NULL,
1852 if (sigfile[0] == '|')
1853 compose_exec_sig(compose, sigfile);
1855 compose_insert_file(compose, sigfile);
1859 static void compose_insert_file(Compose *compose, const gchar *file)
1861 GtkSText *text = GTK_STEXT(compose->text);
1862 gchar buf[BUFFSIZE];
1866 g_return_if_fail(file != NULL);
1868 if ((fp = fopen(file, "rb")) == NULL) {
1869 FILE_OP_ERROR(file, "fopen");
1873 gtk_stext_freeze(text);
1875 while (fgets(buf, sizeof(buf), fp) != NULL) {
1876 /* strip <CR> if DOS/Windows file,
1877 replace <CR> with <LF> if Macintosh file. */
1880 if (len > 0 && buf[len - 1] != '\n') {
1882 if (buf[len] == '\r') buf[len] = '\n';
1884 gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
1887 gtk_stext_thaw(text);
1892 static void compose_attach_append(Compose *compose, const gchar *file,
1893 const gchar *filename,
1894 const gchar *content_type)
1897 gchar *text[N_ATTACH_COLS];
1902 if (!is_file_exist(file)) {
1903 g_warning(_("File %s doesn't exist\n"), file);
1906 if ((size = get_file_size(file)) < 0) {
1907 g_warning(_("Can't get file size of %s\n"), file);
1911 alertpanel_notice(_("File %s is empty."), file);
1914 if ((fp = fopen(file, "rb")) == NULL) {
1915 alertpanel_error(_("Can't read %s."), file);
1920 #if 0 /* NEW COMPOSE GUI */
1921 if (!compose->use_attach) {
1922 GtkItemFactory *ifactory;
1923 GtkWidget *menuitem;
1925 ifactory = gtk_item_factory_from_widget(compose->menubar);
1926 menuitem = gtk_item_factory_get_item(ifactory,
1927 "/View/Attachment");
1928 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
1932 ainfo = g_new0(AttachInfo, 1);
1933 ainfo->file = g_strdup(file);
1936 ainfo->content_type = g_strdup(content_type);
1937 if (!strcasecmp(content_type, "message/rfc822")) {
1938 ainfo->encoding = ENC_7BIT;
1939 ainfo->name = g_strdup_printf
1941 g_basename(filename ? filename : file));
1943 if (!g_strncasecmp(content_type, "text", 4))
1945 procmime_get_encoding_for_file(file);
1947 ainfo->encoding = ENC_BASE64;
1948 ainfo->name = g_strdup
1949 (g_basename(filename ? filename : file));
1952 ainfo->content_type = procmime_get_mime_type(file);
1953 if (!ainfo->content_type) {
1954 ainfo->content_type =
1955 g_strdup("application/octet-stream");
1956 ainfo->encoding = ENC_BASE64;
1957 } else if (!g_strncasecmp(ainfo->content_type, "text", 4))
1958 ainfo->encoding = procmime_get_encoding_for_file(file);
1960 ainfo->encoding = ENC_BASE64;
1961 ainfo->name = g_strdup(g_basename(filename ? filename : file));
1965 text[COL_MIMETYPE] = ainfo->content_type;
1966 text[COL_SIZE] = to_human_readable(size);
1967 text[COL_NAME] = ainfo->name;
1969 row = gtk_clist_append(GTK_CLIST(compose->attach_clist), text);
1970 gtk_clist_set_row_data(GTK_CLIST(compose->attach_clist), row, ainfo);
1973 #define IS_FIRST_PART_TEXT(info) \
1974 ((info->mime_type == MIME_TEXT || info->mime_type == MIME_TEXT_HTML || \
1975 info->mime_type == MIME_TEXT_ENRICHED) || \
1976 (info->mime_type == MIME_MULTIPART && info->content_type && \
1977 !strcasecmp(info->content_type, "multipart/alternative") && \
1978 (info->children && \
1979 (info->children->mime_type == MIME_TEXT || \
1980 info->children->mime_type == MIME_TEXT_HTML || \
1981 info->children->mime_type == MIME_TEXT_ENRICHED))))
1983 static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
1990 mimeinfo = procmime_scan_message(msginfo);
1991 if (!mimeinfo) return;
1993 /* skip first text (presumably message body) */
1994 child = mimeinfo->children;
1995 if (!child || IS_FIRST_PART_TEXT(mimeinfo)) {
1996 procmime_mimeinfo_free_all(mimeinfo);
2000 if (IS_FIRST_PART_TEXT(child))
2001 child = child->next;
2003 infile = procmsg_get_message_file_path(msginfo);
2005 while (child != NULL) {
2006 if (child->children || child->mime_type == MIME_MULTIPART) {
2007 child = procmime_mimeinfo_next(child);
2010 if(child->parent && child->parent->parent
2011 && !strcasecmp(child->parent->parent->content_type, "multipart/signed")
2012 && child->mime_type == MIME_TEXT) {
2013 /* this is the main text part of a signed message */
2014 child = procmime_mimeinfo_next(child);
2017 outfile = procmime_get_tmp_file_name(child);
2018 if (procmime_get_part(outfile, infile, child) < 0)
2019 g_warning(_("Can't get the part of multipart message."));
2020 else if (compose->mode != COMPOSE_REEDIT || strcmp(child->content_type, "application/pgp-signature"))
2021 compose_attach_append
2023 child->filename ? child->filename : child->name,
2024 child->content_type);
2026 child = child->next;
2030 procmime_mimeinfo_free_all(mimeinfo);
2033 #undef IS_FIRST_PART_TEXT
2035 #define GET_CHAR(pos, buf, len) \
2037 if (text->use_wchar) \
2038 len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos))); \
2040 buf[0] = GTK_STEXT_INDEX(text, (pos)); \
2045 #define INDENT_CHARS ">|#"
2046 #define SPACE_CHARS " \t"
2048 static void compose_wrap_line(Compose *compose)
2050 GtkSText *text = GTK_STEXT(compose->text);
2051 gint ch_len, last_ch_len;
2052 gchar cbuf[MB_LEN_MAX], last_ch;
2056 gint p_start, p_end;
2057 gint line_pos, cur_pos;
2058 gint line_len, cur_len;
2060 gtk_stext_freeze(text);
2062 text_len = gtk_stext_get_length(text);
2064 /* check to see if the point is on the paragraph mark (empty line). */
2065 cur_pos = gtk_stext_get_point(text);
2066 GET_CHAR(cur_pos, cbuf, ch_len);
2067 if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
2069 goto compose_end; /* on the paragraph mark */
2070 GET_CHAR(cur_pos - 1, cbuf, ch_len);
2071 if (ch_len == 1 && *cbuf == '\n')
2072 goto compose_end; /* on the paragraph mark */
2075 /* find paragraph start. */
2076 line_end = quoted = 0;
2077 for (p_start = cur_pos; p_start >= 0; --p_start) {
2078 GET_CHAR(p_start, cbuf, ch_len);
2079 if (ch_len == 1 && *cbuf == '\n') {
2081 goto compose_end; /* quoted part */
2089 && strchr(prefs_common.quote_chars, *cbuf))
2091 else if (ch_len != 1 || !isspace(*cbuf))
2100 /* find paragraph end. */
2102 for (p_end = cur_pos; p_end < text_len; p_end++) {
2103 GET_CHAR(p_end, cbuf, ch_len);
2104 if (ch_len == 1 && *cbuf == '\n') {
2111 if (line_end && ch_len == 1 &&
2112 strchr(prefs_common.quote_chars, *cbuf))
2113 goto compose_end; /* quoted part */
2118 if (p_end >= text_len)
2121 if (p_start >= p_end)
2124 line_len = cur_len = 0;
2128 for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
2131 GET_CHAR(cur_pos, cbuf, ch_len);
2138 if (ch_len == 1 && isspace(*cbuf))
2141 if (ch_len == 1 && *cbuf == '\n') {
2143 if (last_ch_len == 1 && !isspace(last_ch)) {
2144 if (cur_pos + 1 < p_end) {
2145 GET_CHAR(cur_pos + 1, cbuf, ch_len);
2146 if (ch_len == 1 && !isspace(*cbuf))
2150 gtk_stext_set_point(text, cur_pos + 1);
2151 gtk_stext_backward_delete(text, 1);
2153 gtk_stext_set_point(text, cur_pos);
2154 gtk_stext_insert(text, NULL, NULL, NULL, " ", 1);
2164 last_ch_len = ch_len;
2168 line_pos = cur_pos + 1;
2169 line_len = cur_len + ch_len;
2172 if (cur_len + ch_len > prefs_common.linewrap_len &&
2176 GET_CHAR(line_pos - 1, cbuf, ch_len);
2177 if (ch_len == 1 && isspace(*cbuf)) {
2178 gtk_stext_set_point(text, line_pos);
2179 gtk_stext_backward_delete(text, 1);
2188 gtk_stext_set_point(text, line_pos);
2189 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2193 cur_len = cur_len - line_len + ch_len;
2199 line_pos = cur_pos + 1;
2200 line_len = cur_len + ch_len;
2206 gtk_stext_thaw(text);
2211 /* Darko: used when I debug wrapping */
2212 void dump_text(GtkSText *text, int pos, int tlen, int breakoncr)
2215 gchar cbuf[MB_LEN_MAX];
2217 printf("%d [", pos);
2218 for (i = pos; i < tlen; i++) {
2219 GET_CHAR(i, cbuf, clen);
2220 if (clen < 0) break;
2221 if (breakoncr && clen == 1 && cbuf[0] == '\n')
2223 fwrite(cbuf, clen, 1, stdout);
2231 WAIT_FOR_INDENT_CHAR,
2232 WAIT_FOR_INDENT_CHAR_OR_SPACE
2235 /* return indent length, we allow:
2236 > followed by spaces/tabs
2237 | followed by spaces/tabs
2238 uppercase characters immediately followed by >,
2239 and the repeating sequences of the above */
2240 /* return indent length */
2241 static guint get_indent_length(GtkSText *text, guint start_pos, guint text_len)
2244 guint i, ch_len, alnum_cnt = 0;
2245 IndentState state = WAIT_FOR_INDENT_CHAR;
2246 gchar cbuf[MB_LEN_MAX];
2250 for (i = start_pos; i < text_len; i++) {
2251 GET_CHAR(i, cbuf, ch_len);
2255 if (cbuf[0] == '\n')
2258 is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
2259 is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
2262 case WAIT_FOR_SPACE:
2263 if (is_space == FALSE)
2265 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2267 case WAIT_FOR_INDENT_CHAR_OR_SPACE:
2268 if (is_indent == FALSE && is_space == FALSE &&
2271 if (is_space == TRUE) {
2273 state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
2274 } else if (is_indent == TRUE) {
2276 state = WAIT_FOR_SPACE;
2279 state = WAIT_FOR_INDENT_CHAR;
2282 case WAIT_FOR_INDENT_CHAR:
2283 if (is_indent == FALSE && !isupper(cbuf[0]))
2285 if (is_indent == TRUE) {
2287 && !strchr(prefs_common.quote_chars, cbuf[0]))
2290 state = WAIT_FOR_SPACE;
2301 if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
2307 /* insert quotation string when line was wrapped */
2308 static guint ins_quote(GtkSText *text, guint indent_len,
2309 guint prev_line_pos, guint text_len,
2312 guint i, ins_len = 0;
2316 for (i = 0; i < indent_len; i++) {
2317 ch = GTK_STEXT_INDEX(text, prev_line_pos + i);
2318 gtk_stext_insert(text, NULL, NULL, NULL, &ch, 1);
2320 ins_len = indent_len;
2326 /* check if we should join the next line */
2327 static gboolean join_next_line(GtkSText *text, guint start_pos, guint tlen,
2328 guint prev_ilen, gboolean autowrap)
2330 guint indent_len, ch_len;
2331 gboolean do_join = FALSE;
2332 gchar cbuf[MB_LEN_MAX];
2334 indent_len = get_indent_length(text, start_pos, tlen);
2336 if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
2337 GET_CHAR(start_pos + indent_len, cbuf, ch_len);
2338 if (ch_len > 0 && (cbuf[0] != '\n'))
2345 static void compose_wrap_line_all(Compose *compose)
2347 compose_wrap_line_all_full(compose, FALSE);
2350 #define STEXT_FREEZE() \
2351 if (!frozen) { gtk_stext_freeze(text); frozen = TRUE; }
2353 static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
2355 GtkSText *text = GTK_STEXT(compose->text);
2357 guint line_pos = 0, cur_pos = 0, p_pos = 0;
2358 gint line_len = 0, cur_len = 0;
2360 gboolean is_new_line = TRUE, do_delete = FALSE;
2362 gboolean linewrap_quote = TRUE;
2363 gboolean set_editable_pos = FALSE;
2364 gint editable_pos = 0;
2365 gboolean frozen = FALSE;
2366 guint linewrap_len = prefs_common.linewrap_len;
2367 gchar *qfmt = prefs_common.quotemark;
2368 gchar cbuf[MB_LEN_MAX];
2370 tlen = gtk_stext_get_length(text);
2372 for (; cur_pos < tlen; cur_pos++) {
2373 /* mark position of new line - needed for quotation wrap */
2376 i_len = get_indent_length(text, cur_pos, tlen);
2378 is_new_line = FALSE;
2381 g_print("new line i_len=%d p_pos=", i_len);
2382 dump_text(text, p_pos, tlen, 1);
2386 GET_CHAR(cur_pos, cbuf, ch_len);
2388 /* fix line length for tabs */
2389 if (ch_len == 1 && *cbuf == '\t') {
2390 guint tab_width = text->default_tab_width;
2391 guint tab_offset = line_len % tab_width;
2394 g_print("found tab at pos=%d line_len=%d ", cur_pos,
2398 line_len += tab_width - tab_offset - 1;
2402 printf("new_len=%d\n", line_len);
2406 /* we have encountered line break */
2407 if (ch_len == 1 && *cbuf == '\n') {
2409 gchar cb[MB_LEN_MAX];
2411 /* should we join the next line */
2412 if ((autowrap || i_len != cur_len) && do_delete &&
2414 (text, cur_pos + 1, tlen, i_len, autowrap))
2420 g_print("found CR at %d do_del is %d next line is ",
2421 cur_pos, do_delete);
2422 dump_text(text, cur_pos + 1, tlen, 1);
2425 /* skip delete if it is continuous URL */
2426 if (do_delete && (line_pos - p_pos <= i_len) &&
2427 gtkut_stext_is_uri_string(text, line_pos, tlen))
2431 g_print("l_len=%d wrap_len=%d do_del=%d\n",
2432 line_len, linewrap_len, do_delete);
2434 /* should we delete to perform smart wrapping */
2435 if (line_len < linewrap_len && do_delete) {
2437 /* get rid of newline */
2438 gtk_stext_set_point(text, cur_pos);
2439 gtk_stext_forward_delete(text, 1);
2442 /* if text starts with quote fmt or with
2443 indent string, delete them */
2446 ilen = gtkut_stext_str_compare_n
2447 (text, cur_pos, p_pos, i_len,
2450 gtk_stext_forward_delete
2456 GET_CHAR(cur_pos, cb, clen);
2458 /* insert space if it's alphanumeric */
2459 if ((cur_pos != line_pos) &&
2460 ((clen > 1) || isalnum(cb[0]))) {
2461 gtk_stext_insert(text, NULL, NULL,
2466 /* and start over with current line */
2467 cur_pos = p_pos - 1;
2469 line_len = cur_len = 0;
2473 g_print("after delete l_pos=");
2474 dump_text(text, line_pos, tlen, 1);
2479 /* mark new line beginning */
2480 line_pos = cur_pos + 1;
2481 line_len = cur_len = 0;
2492 /* possible line break */
2493 if (ch_len == 1 && isspace(*cbuf)) {
2494 line_pos = cur_pos + 1;
2495 line_len = cur_len + ch_len;
2498 /* are we over wrapping length set in preferences ? */
2499 if (cur_len + ch_len > linewrap_len) {
2503 g_print("should wrap cur_pos=%d ", cur_pos);
2504 dump_text(text, p_pos, tlen, 1);
2505 dump_text(text, line_pos, tlen, 1);
2507 /* force wrapping if it is one long word but not URL */
2508 if (line_pos - p_pos <= i_len)
2509 if (!gtkut_stext_is_uri_string
2510 (text, line_pos, tlen))
2511 line_pos = cur_pos - 1;
2513 g_print("new line_pos=%d\n", line_pos);
2516 GET_CHAR(line_pos - 1, cbuf, clen);
2518 /* if next character is space delete it */
2519 if (clen == 1 && isspace(*cbuf)) {
2520 if (p_pos + i_len != line_pos ||
2521 !gtkut_stext_is_uri_string
2522 (text, line_pos, tlen)) {
2524 /* workaround for correct cursor
2526 if (set_editable_pos == FALSE) {
2527 editable_pos = gtk_editable_get_position(GTK_EDITABLE(text));
2528 if (editable_pos == line_pos)
2529 set_editable_pos = TRUE;
2531 gtk_stext_set_point(text, line_pos);
2532 gtk_stext_backward_delete(text, 1);
2541 /* if it is URL at beginning of line don't wrap */
2542 if (p_pos + i_len == line_pos &&
2543 gtkut_stext_is_uri_string(text, line_pos, tlen)) {
2545 g_print("found URL at ");
2546 dump_text(text, line_pos, tlen, 1);
2553 gtk_stext_set_point(text, line_pos);
2554 gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
2555 /* gtk_stext_compact_buffer(text); */
2558 /* for loop will increase it */
2559 cur_pos = line_pos - 1;
2560 /* start over with current line */
2562 line_len = cur_len = 0;
2563 if (autowrap || i_len > 0)
2568 g_print("after CR insert ");
2569 dump_text(text, line_pos, tlen, 1);
2570 dump_text(text, cur_pos, tlen, 1);
2573 /* should we insert quotation ? */
2574 if (linewrap_quote && i_len) {
2575 /* only if line is not already quoted */
2576 if (!gtkut_stext_str_compare
2577 (text, line_pos, tlen, qfmt)) {
2580 if (line_pos - p_pos > i_len) {
2582 (text, i_len, p_pos,
2587 g_print("after quote insert ");
2588 dump_text(text, line_pos, tlen, 1);
2596 line_pos = cur_pos + 1;
2597 line_len = cur_len + ch_len;
2599 /* advance to next character in buffer */
2604 gtk_stext_thaw(text);
2606 if (set_editable_pos && editable_pos <= tlen)
2607 gtk_editable_set_position(GTK_EDITABLE(text), editable_pos);
2613 static void compose_set_title(Compose *compose)
2618 edited = compose->modified ? _(" [Edited]") : "";
2619 if (compose->account && compose->account->address)
2620 str = g_strdup_printf(_("%s - Compose message%s"),
2621 compose->account->address, edited);
2623 str = g_strdup_printf(_("Compose message%s"), edited);
2624 gtk_window_set_title(GTK_WINDOW(compose->window), str);
2629 * compose_current_mail_account:
2631 * Find a current mail account (the currently selected account, or the
2632 * default account, if a news account is currently selected). If a
2633 * mail account cannot be found, display an error message.
2635 * Return value: Mail account, or NULL if not found.
2637 static PrefsAccount *
2638 compose_current_mail_account(void)
2642 if (cur_account && cur_account->protocol != A_NNTP)
2645 ac = account_get_default();
2646 if (!ac || ac->protocol == A_NNTP) {
2647 alertpanel_error(_("Account for sending mail is not specified.\n"
2648 "Please select a mail account before sending."));
2655 static void compose_select_account(Compose *compose, PrefsAccount *account)
2657 GtkWidget *menuitem;
2658 GtkItemFactory *ifactory;
2660 g_return_if_fail(account != NULL);
2662 compose->account = account;
2664 compose_set_title(compose);
2666 ifactory = gtk_item_factory_from_widget(compose->menubar);
2668 if (account->protocol == A_NNTP) {
2669 gtk_widget_show(compose->newsgroups_hbox);
2670 gtk_widget_show(compose->newsgroups_entry);
2671 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 4);
2673 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2674 gtk_check_menu_item_set_active
2675 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2676 gtk_widget_set_sensitive(menuitem, TRUE);
2677 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2678 gtk_check_menu_item_set_active
2679 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2680 gtk_widget_set_sensitive(menuitem, TRUE);
2682 menu_set_sensitive(ifactory, "/View/Followup to", TRUE);
2684 gtk_widget_hide(compose->newsgroups_hbox);
2685 gtk_widget_hide(compose->newsgroups_entry);
2686 gtk_table_set_row_spacing(GTK_TABLE(compose->table), 2, 0);
2687 gtk_widget_queue_resize(compose->table_vbox);
2689 menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
2690 gtk_check_menu_item_set_active
2691 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2692 gtk_widget_set_sensitive(menuitem, FALSE);
2693 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2694 gtk_check_menu_item_set_active
2695 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2696 gtk_widget_set_sensitive(menuitem, FALSE);
2698 menuitem = gtk_item_factory_get_item(ifactory, "/View/Followup to");
2699 gtk_check_menu_item_set_active
2700 (GTK_CHECK_MENU_ITEM(menuitem), FALSE);
2701 gtk_widget_set_sensitive(menuitem, FALSE);
2704 if (account->set_autocc && account->auto_cc &&
2705 compose->mode != COMPOSE_REEDIT) {
2707 (GTK_ENTRY(compose->cc_entry), account->auto_cc);
2708 menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
2709 gtk_check_menu_item_set_active
2710 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2712 if (account->set_autobcc) {
2713 menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
2714 gtk_check_menu_item_set_active
2715 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2716 if (account->auto_bcc && compose->mode != COMPOSE_REEDIT)
2717 gtk_entry_set_text(GTK_ENTRY(compose->bcc_entry),
2720 if (account->set_autoreplyto) {
2721 menuitem = gtk_item_factory_get_item(ifactory,
2723 gtk_check_menu_item_set_active
2724 (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
2725 if (account->auto_replyto && compose->mode != COMPOSE_REEDIT)
2726 gtk_entry_set_text(GTK_ENTRY(compose->reply_entry),
2727 account->auto_replyto);
2730 menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
2731 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2732 prefs_common.show_ruler);
2736 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
2737 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2738 account->default_sign);
2739 menuitem = gtk_item_factory_get_item(ifactory, "/Message/Encrypt");
2740 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
2741 account->default_encrypt);
2742 #endif /* USE_GPGME */
2745 gboolean compose_check_for_valid_recipient(Compose *compose) {
2746 gchar *recipient_headers_mail[] = {"To:", "Cc:", "Bcc:", NULL};
2747 gchar *recipient_headers_news[] = {"Newsgroups:", NULL};
2748 gboolean recipient_found = FALSE;
2752 /* free to and newsgroup list */
2753 slist_free_strings(compose->to_list);
2754 g_slist_free(compose->to_list);
2755 compose->to_list = NULL;
2757 slist_free_strings(compose->newsgroup_list);
2758 g_slist_free(compose->newsgroup_list);
2759 compose->newsgroup_list = NULL;
2761 /* search header entries for to and newsgroup entries */
2762 for (list = compose->header_list; list; list = list->next) {
2765 header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
2766 entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
2768 if (entry[0] != '\0') {
2769 for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
2770 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2771 compose->to_list = address_list_append(compose->to_list, entry);
2772 recipient_found = TRUE;
2775 for (strptr = recipient_headers_news; *strptr != NULL; strptr++) {
2776 if (!strcmp(header, (prefs_common.trans_hdr ? gettext(*strptr) : *strptr))) {
2777 compose->newsgroup_list = newsgroup_list_append(compose->newsgroup_list, entry);
2778 recipient_found = TRUE;
2785 return recipient_found;
2788 static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
2792 if (compose_check_for_valid_recipient(compose) == FALSE) {
2793 alertpanel_error(_("Recipient is not specified."));
2797 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
2798 if (*str == '\0' && check_subject == TRUE) {
2801 aval = alertpanel(_("Send"),
2802 _("Subject is empty. Send it anyway?"),
2803 _("Yes"), _("No"), NULL);
2804 if (aval != G_ALERTDEFAULT)
2811 gint compose_send(Compose *compose)
2818 if (compose_check_entries(compose, TRUE) == FALSE)
2821 val = compose_queue(compose, &msgnum, &folder);
2823 alertpanel_error(_("Could not queue message for sending"));
2827 msgpath = folder_item_fetch_msg(folder, msgnum);
2828 val = procmsg_send_message_queue(msgpath);
2831 folder_item_remove_msg(folder, msgnum);
2832 folderview_update_item(folder, TRUE);
2837 #if 0 /* compose restructure */
2838 gint compose_send(Compose *compose)
2840 gchar tmp[MAXPATHLEN + 1];
2842 static gboolean lock = FALSE;
2846 g_return_val_if_fail(compose->account != NULL, -1);
2847 g_return_val_if_fail(compose->orig_account != NULL, -1);
2851 if (compose_check_entries(compose, TRUE) == FALSE) {
2856 /* write to temporary file */
2857 g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
2858 get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
2860 if (prefs_common.linewrap_at_send)
2861 compose_wrap_line_all(compose);
2863 if (compose_write_to_file(compose, tmp, FALSE) < 0) {
2868 if (!compose->to_list && !compose->newsgroup_list) {
2869 g_warning(_("can't get recipient list."));
2875 if (compose->to_list) {
2878 #if 0 /* NEW COMPOSE GUI */
2879 if (compose->account->protocol != A_NNTP)
2880 ac = compose->account;
2881 else if (compose->orig_account->protocol != A_NNTP)
2882 ac = compose->orig_account;
2883 else if (cur_account && cur_account->protocol != A_NNTP)
2886 ac = compose_current_mail_account();
2894 ac = compose->account;
2896 ok = send_message(tmp, ac, compose->to_list);
2897 statusbar_pop_all();
2900 if (ok == 0 && compose->newsgroup_list) {
2903 if (compose->account->protocol == A_NNTP)
2904 folder = FOLDER(compose->account->folder);
2906 folder = FOLDER(compose->orig_account->folder);
2908 ok = news_post(folder, tmp);
2910 alertpanel_error(_("Error occurred while posting the message to %s ."),
2911 compose->account->nntp_server);
2918 /* queue message if failed to send */
2920 if (prefs_common.queue_msg) {
2925 _("Error occurred while sending the message.\n"
2926 "Put this message into queue folder?"),
2927 _("OK"), _("Cancel"), NULL);
2928 if (G_ALERTDEFAULT == val) {
2929 ok = compose_queue(compose, tmp);
2931 alertpanel_error(_("Can't queue the message."));
2934 alertpanel_error(_("Error occurred while sending the message."));
2936 if (compose->mode == COMPOSE_REEDIT) {
2937 compose_remove_reedit_target(compose);
2938 if (compose->targetinfo)
2939 folderview_update_item
2940 (compose->targetinfo->folder, TRUE);
2942 /* save message to outbox */
2943 if (prefs_common.savemsg) {
2946 outbox = account_get_special_folder
2947 (compose->account, F_OUTBOX);
2948 if (procmsg_save_to_outbox(outbox, tmp, FALSE) < 0)
2950 (_("Can't save the message to Sent."));
2952 folderview_update_item(outbox, TRUE);
2962 static gboolean compose_use_attach(Compose *compose) {
2963 return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
2966 static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
2969 gchar buf[BUFFSIZE];
2971 gboolean first_address;
2973 ComposeHeaderEntry *headerentry;
2974 gchar *headerentryname;
2978 debug_print("Writing redirect header\n");
2980 cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
2981 to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
2983 first_address = TRUE;
2984 for (list = compose->header_list; list; list = list->next) {
2985 headerentry = ((ComposeHeaderEntry *)list->data);
2986 headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
2988 if (g_strcasecmp(headerentryname, cc_hdr) == 0
2989 || g_strcasecmp(headerentryname, to_hdr) == 0) {
2990 str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
2991 Xstrdup_a(str, str, return -1);
2993 if (str[0] != '\0') {
2994 compose_convert_header
2995 (buf, sizeof(buf), str,
2996 strlen("Resent-To") + 2);
2997 if (first_address) {
2998 fprintf(fp, "Resent-To: ");
2999 first_address = FALSE;
3003 fprintf(fp, "%s", buf);
3007 /* if (!first_address) { */
3014 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
3016 gchar buf[BUFFSIZE];
3018 /* struct utsname utsbuf; */
3020 g_return_val_if_fail(fp != NULL, -1);
3021 g_return_val_if_fail(compose->account != NULL, -1);
3022 g_return_val_if_fail(compose->account->address != NULL, -1);
3025 get_rfc822_date(buf, sizeof(buf));
3026 fprintf(fp, "Resent-Date: %s\n", buf);
3029 if (compose->account->name && *compose->account->name) {
3030 compose_convert_header
3031 (buf, sizeof(buf), compose->account->name,
3033 fprintf(fp, "Resent-From: %s <%s>\n",
3034 buf, compose->account->address);
3036 fprintf(fp, "Resent-From: %s\n", compose->account->address);
3039 str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
3041 Xstrdup_a(str, str, return -1);
3044 compose_convert_header(buf, sizeof(buf), str,
3045 strlen("Subject: "));
3046 fprintf(fp, "Subject: %s\n", buf);
3050 /* Resent-Message-ID */
3051 if (compose->account->gen_msgid) {
3052 compose_generate_msgid(compose, buf, sizeof(buf));
3053 fprintf(fp, "Resent-Message-Id: <%s>\n", buf);
3054 compose->msgid = g_strdup(buf);
3057 compose_redirect_write_headers_from_headerlist(compose, fp);
3059 /* separator between header and body */
3065 static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
3070 gchar buf[BUFFSIZE];
3072 if ((fp = fopen(compose->redirect_filename, "rb")) == NULL) {
3073 FILE_OP_ERROR(file, "fopen");
3077 if ((fdest = fopen(file, "wb")) == NULL) {
3078 FILE_OP_ERROR(file, "fopen");
3083 /* chmod for security */
3084 if (change_file_mode_rw(fdest, file) < 0) {
3085 FILE_OP_ERROR(file, "chmod");
3086 g_warning(_("can't change file mode\n"));
3089 while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
3090 /* should filter returnpath, delivered-to */
3091 if (g_strncasecmp(buf, "Return-Path:",
3092 strlen("Return-Path:")) == 0 ||
3093 g_strncasecmp(buf, "Delivered-To:",
3094 strlen("Delivered-To:")) == 0 ||
3095 g_strncasecmp(buf, "Received:",
3096 strlen("Received:")) == 0 ||
3097 g_strncasecmp(buf, "Subject:",
3098 strlen("Subject:")) == 0 ||
3099 g_strncasecmp(buf, "X-UIDL:",
3100 strlen("X-UIDL:")) == 0)
3103 if (fputs(buf, fdest) == -1)
3106 if (!prefs_common.redirect_keep_from) {
3107 if (g_strncasecmp(buf, "From:",
3108 strlen("From:")) == 0) {
3109 fputs(" (by way of ", fdest);
3110 if (compose->account->name
3111 && *compose->account->name) {
3112 compose_convert_header
3114 compose->account->name,
3116 fprintf(fdest, "%s <%s>",
3118 compose->account->address);
3120 fprintf(fdest, "%s",
3121 compose->account->address);
3126 if (fputs("\n", fdest) == -1)
3130 compose_redirect_write_headers(compose, fdest);
3132 while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
3133 if (fwrite(buf, sizeof(gchar), len, fdest) != len) {
3134 FILE_OP_ERROR(file, "fwrite");
3140 if (fclose(fdest) == EOF) {
3141 FILE_OP_ERROR(file, "fclose");
3157 /* interfaces to rfc2015 to keep out the prefs stuff there.
3158 * returns 0 on success and -1 on error. */
3159 static gint compose_create_signers_list(Compose *compose, GSList **pkey_list)
3161 const gchar *key_id = NULL;
3164 switch (compose->account->sign_key) {
3165 case SIGN_KEY_DEFAULT:
3168 case SIGN_KEY_BY_FROM:
3169 key_id = compose->account->address;
3171 case SIGN_KEY_CUSTOM:
3172 key_id = compose->account->sign_key_id;
3178 key_list = rfc2015_create_signers_list(key_id);
3181 alertpanel_error(_("Could not find any key associated with "
3182 "currently selected key id `%s'."), key_id);
3186 *pkey_list = key_list;
3190 /* clearsign message body text */
3191 static gint compose_clearsign_text(Compose *compose, gchar **text)
3196 tmp_file = get_tmp_file();
3197 if (str_write_to_file(*text, tmp_file) < 0) {
3202 if (canonicalize_file_replace(tmp_file) < 0 ||
3203 compose_create_signers_list(compose, &key_list) < 0 ||
3204 rfc2015_clearsign(tmp_file, key_list) < 0) {
3211 *text = file_read_to_str(tmp_file);
3219 #endif /* USE_GPGME */
3221 static gint compose_write_to_file(Compose *compose, const gchar *file,
3228 const gchar *out_codeset;
3229 EncodingType encoding;
3231 if ((fp = fopen(file, "wb")) == NULL) {
3232 FILE_OP_ERROR(file, "fopen");
3236 /* chmod for security */
3237 if (change_file_mode_rw(fp, file) < 0) {
3238 FILE_OP_ERROR(file, "chmod");
3239 g_warning(_("can't change file mode\n"));
3242 /* get all composed text */
3243 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3244 len = strlen(chars);
3245 if (is_ascii_str(chars)) {
3248 out_codeset = CS_US_ASCII;
3249 encoding = ENC_7BIT;
3251 const gchar *src_codeset;
3253 out_codeset = conv_get_outgoing_charset_str();
3254 if (!strcasecmp(out_codeset, CS_US_ASCII))
3255 out_codeset = CS_ISO_8859_1;
3256 encoding = procmime_get_encoding_for_charset(out_codeset);
3260 compose->use_signing && !compose->account->clearsign &&
3261 encoding == ENC_8BIT)
3262 encoding = ENC_BASE64;
3265 src_codeset = conv_get_current_charset_str();
3266 /* if current encoding is US-ASCII, set it the same as
3267 outgoing one to prevent code conversion failure */
3268 if (!strcasecmp(src_codeset, CS_US_ASCII))
3269 src_codeset = out_codeset;
3271 debug_print("src encoding = %s, out encoding = %s, transfer encoding = %s\n",
3272 src_codeset, out_codeset, procmime_get_encoding_str(encoding));
3274 buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
3280 _("Can't convert the character encoding of the message.\n"
3281 "Send it anyway?"), _("Yes"), _("+No"), NULL);
3282 if (aval != G_ALERTDEFAULT) {
3296 if (!is_draft && compose->use_signing && compose->account->clearsign) {
3297 if (compose_clearsign_text(compose, &buf) < 0) {
3298 g_warning("clearsign failed\n");
3308 if (compose_write_headers
3309 (compose, fp, out_codeset, encoding, is_draft) < 0) {
3310 g_warning(_("can't write headers\n"));
3317 if (compose_use_attach(compose)) {
3319 /* This prolog message is ignored by mime software and
3320 * because it would make our signing/encryption task
3321 * tougher, we don't emit it in that case */
3322 if (!compose->use_signing && !compose->use_encryption)
3324 fputs("This is a multi-part message in MIME format.\n", fp);
3326 fprintf(fp, "\n--%s\n", compose->boundary);
3327 fprintf(fp, "Content-Type: text/plain; charset=%s\n",
3329 fprintf(fp, "Content-Transfer-Encoding: %s\n",
3330 procmime_get_encoding_str(encoding));
3336 if (encoding == ENC_BASE64) {
3337 gchar outbuf[B64_BUFFSIZE];
3340 for (i = 0; i < len; i += B64_LINE_SIZE) {
3341 l = MIN(B64_LINE_SIZE, len - i);
3342 base64_encode(outbuf, buf + i, l);
3346 } else if (fwrite(buf, sizeof(gchar), len, fp) != len) {
3347 FILE_OP_ERROR(file, "fwrite");
3355 if (compose_use_attach(compose))
3356 compose_write_attach(compose, fp);
3358 if (fclose(fp) == EOF) {
3359 FILE_OP_ERROR(file, "fclose");
3368 if ((compose->use_signing && !compose->account->clearsign) ||
3369 compose->use_encryption) {
3370 if (canonicalize_file_replace(file) < 0) {
3376 if (compose->use_signing && !compose->account->clearsign) {
3379 if (compose_create_signers_list(compose, &key_list) < 0 ||
3380 rfc2015_sign(file, key_list) < 0) {
3385 if (compose->use_encryption) {
3386 if (rfc2015_encrypt(file, compose->to_list,
3387 compose->account->ascii_armored) < 0) {
3392 #endif /* USE_GPGME */
3397 static gint compose_write_body_to_file(Compose *compose, const gchar *file)
3403 if ((fp = fopen(file, "wb")) == NULL) {
3404 FILE_OP_ERROR(file, "fopen");
3408 /* chmod for security */
3409 if (change_file_mode_rw(fp, file) < 0) {
3410 FILE_OP_ERROR(file, "chmod");
3411 g_warning(_("can't change file mode\n"));
3414 chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
3417 len = strlen(chars);
3418 if (fwrite(chars, sizeof(gchar), len, fp) != len) {
3419 FILE_OP_ERROR(file, "fwrite");
3428 if (fclose(fp) == EOF) {
3429 FILE_OP_ERROR(file, "fclose");
3436 static gint compose_remove_reedit_target(Compose *compose)
3439 MsgInfo *msginfo = compose->targetinfo;
3441 g_return_val_if_fail(compose->mode == COMPOSE_REEDIT, -1);
3442 if (!msginfo) return -1;
3444 item = msginfo->folder;
3445 g_return_val_if_fail(item != NULL, -1);
3447 if (procmsg_msg_exist(msginfo) &&
3448 (item->stype == F_DRAFT || item->stype == F_QUEUE)) {
3449 if (folder_item_remove_msg(item, msginfo->msgnum) < 0) {
3450 g_warning(_("can't remove the old message\n"));
3458 void compose_remove_draft(Compose *compose)
3461 MsgInfo *msginfo = compose->targetinfo;
3462 drafts = account_get_special_folder(compose->account, F_DRAFT);
3464 if (procmsg_msg_exist(msginfo)) {
3465 folder_item_remove_msg(drafts, msginfo->msgnum);
3466 folderview_update_item(drafts, TRUE);
3471 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
3473 return compose_queue_sub (compose, msgnum, item, FALSE);
3475 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, gboolean check_subject)
3481 gchar buf[BUFFSIZE];
3483 static gboolean lock = FALSE;
3484 PrefsAccount *mailac = NULL, *newsac = NULL;
3486 debug_print("queueing message...\n");
3487 g_return_val_if_fail(compose->account != NULL, -1);
3488 g_return_val_if_fail(compose->orig_account != NULL, -1);
3492 if (compose_check_entries(compose, check_subject) == FALSE) {
3497 if (!compose->to_list && !compose->newsgroup_list) {
3498 g_warning(_("can't get recipient list."));
3503 if (compose->to_list) {
3504 if (compose->account->protocol != A_NNTP)
3505 mailac = compose->account;
3506 else if (compose->orig_account->protocol != A_NNTP)
3507 mailac = compose->orig_account;
3508 else if (cur_account && cur_account->protocol != A_NNTP)
3509 mailac = cur_account;
3510 else if (!(mailac = compose_current_mail_account())) {
3512 alertpanel_error(_("No account for sending mails available!"));
3517 if (compose->newsgroup_list) {
3518 if (compose->account->protocol == A_NNTP)
3519 newsac = compose->account;
3520 else if (!(newsac = compose->orig_account) || (newsac->protocol != A_NNTP)) {
3522 alertpanel_error(_("No account for posting news available!"));
3527 if (prefs_common.linewrap_at_send)
3528 compose_wrap_line_all(compose);
3530 /* write to temporary file */
3531 tmp2 = g_strdup_printf("%s%ctmp%d", g_get_tmp_dir(),
3532 G_DIR_SEPARATOR, (gint)compose);
3534 if (compose->redirect_filename != NULL) {
3535 if (compose_redirect_write_to_file(compose, tmp2) < 0) {
3542 if (compose_write_to_file(compose, tmp2, FALSE) < 0) {
3549 /* add queue header */
3550 tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
3551 G_DIR_SEPARATOR, (gint)compose);
3552 if ((fp = fopen(tmp, "wb")) == NULL) {
3553 FILE_OP_ERROR(tmp, "fopen");
3557 if ((src_fp = fopen(tmp2, "rb")) == NULL) {
3558 FILE_OP_ERROR(tmp2, "fopen");
3566 if (change_file_mode_rw(fp, tmp) < 0) {
3567 FILE_OP_ERROR(tmp, "chmod");
3568 g_warning(_("can't change file mode\n"));
3571 /* queueing variables */
3572 fprintf(fp, "AF:\n");
3573 fprintf(fp, "NF:0\n");
3574 fprintf(fp, "PS:10\n");
3575 fprintf(fp, "SRH:1\n");
3576 fprintf(fp, "SFN:\n");
3577 fprintf(fp, "DSR:\n");
3579 fprintf(fp, "MID:<%s>\n", compose->msgid);
3581 fprintf(fp, "MID:\n");
3582 fprintf(fp, "CFG:\n");
3583 fprintf(fp, "PT:0\n");
3584 fprintf(fp, "S:%s\n", compose->account->address);
3585 fprintf(fp, "RQ:\n");
3587 fprintf(fp, "SSV:%s\n", mailac->smtp_server);
3589 fprintf(fp, "SSV:\n");
3591 fprintf(fp, "NSV:%s\n", newsac->nntp_server);
3593 fprintf(fp, "NSV:\n");
3594 fprintf(fp, "SSH:\n");
3595 /* write recepient list */
3597 if (compose->to_list) {
3598 fprintf(fp, "<%s>", (gchar *)compose->to_list->data);
3599 for (cur = compose->to_list->next; cur != NULL; cur = cur->next)
3600 fprintf(fp, ",<%s>", (gchar *)cur->data);
3603 /* write newsgroup list */
3605 if (compose->newsgroup_list) {
3606 fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
3607 for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
3608 fprintf(fp, ",%s", (gchar *)cur->data);
3611 /* Sylpheed account IDs */
3613 fprintf(fp, "MAID:%d\n", mailac->account_id);
3616 fprintf(fp, "NAID:%d\n", newsac->account_id);
3618 /* Save copy folder */
3619 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
3620 gchar *savefolderid;
3622 savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
3623 fprintf(fp, "SCF:%s\n", savefolderid);
3624 g_free(savefolderid);
3626 /* Message-ID of message replying to */
3627 if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
3630 folderid = folder_item_get_identifier(compose->replyinfo->folder);
3631 fprintf(fp, "RMID:%s\x7f%d\x7f%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
3636 while (fgets(buf, sizeof(buf), src_fp) != NULL) {
3637 if (fputs(buf, fp) == EOF) {
3638 FILE_OP_ERROR(tmp, "fputs");
3649 if (fclose(fp) == EOF) {
3650 FILE_OP_ERROR(tmp, "fclose");
3658 queue = account_get_special_folder(compose->account, F_QUEUE);
3660 g_warning(_("can't find queue folder\n"));
3665 folder_item_scan(queue);
3666 if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
3667 g_warning(_("can't queue the message\n"));
3677 if (compose->mode == COMPOSE_REEDIT) {
3678 compose_remove_reedit_target(compose);
3679 if (compose->targetinfo &&
3680 compose->targetinfo->folder != queue)
3681 folderview_update_item
3682 (compose->targetinfo->folder, TRUE);
3685 folderview_update_item(queue, TRUE);
3687 if ((msgnum != NULL) && (item != NULL)) {
3695 static void compose_write_attach(Compose *compose, FILE *fp)
3698 GtkCList *clist = GTK_CLIST(compose->attach_clist);
3701 gchar filename[BUFFSIZE];
3704 for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
3706 gchar buf[BUFFSIZE];
3707 gchar inbuf[B64_LINE_SIZE], outbuf[B64_BUFFSIZE];
3709 if ((attach_fp = fopen(ainfo->file, "rb")) == NULL) {
3710 g_warning(_("Can't open file %s\n"), ainfo->file);
3714 fprintf(fp, "\n--%s\n", compose->boundary);
3716 if (!strcmp2(ainfo->content_type, "message/rfc822")) {
3717 fprintf(fp, "Content-Type: %s\n", ainfo->content_type);
3718 fprintf(fp, "Content-Disposition: inline\n");
3720 conv_encode_header(filename, sizeof(filename),
3722 fprintf(fp, "Content-Type: %s;\n"
3724 ainfo->content_type, filename);
3725 fprintf(fp, "Content-Disposition: attachment;\n"
3726 " filename=\"%s\"\n", filename);
3729 fprintf(fp, "Content-Transfer-Encoding: %s\n\n",
3730 procmime_get_encoding_str(ainfo->encoding));
3732 switch (ainfo->encoding) {
3736 /* if (ainfo->encoding == ENC_7BIT) { */
3738 while (fgets(buf, sizeof(buf), attach_fp) != NULL) {
3746 while ((len = fread(inbuf, sizeof(gchar),
3747 B64_LINE_SIZE, attach_fp))