diff options
Diffstat (limited to 'composer/e-msg-composer.c')
-rw-r--r-- | composer/e-msg-composer.c | 652 |
1 files changed, 182 insertions, 470 deletions
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c index 3195255a52..d1a6abb222 100644 --- a/composer/e-msg-composer.c +++ b/composer/e-msg-composer.c @@ -23,17 +23,6 @@ * */ -/* - - TODO - - - Somehow users should be able to see if any file (s) are attached even when - the attachment bar is not shown. - - Should use EventSources to keep track of global changes made to configuration - values. Right now it ignores the problem olympically. Miguel. -*/ - #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -61,39 +50,33 @@ #include "e-util/e-dialog-utils.h" #include "misc/e-charset-picker.h" #include "e-util/e-error.h" +#include "e-util/e-mktemp.h" #include "e-util/e-plugin-ui.h" #include "e-util/e-util-private.h" -#include "e-util/e-util.h" -#include "e-util/e-mktemp.h" -#include <mail/em-event.h> +#include "e-util/e-account-utils.h" +#include "e-util/e-signature-utils.h" #include "e-signature-combo-box.h" +#include "shell/e-shell.h" -#include <camel/camel-session.h> #include <camel/camel-charset-map.h> +#include <camel/camel-cipher-context.h> +#include <camel/camel-folder.h> +#include <camel/camel-gpg-context.h> #include <camel/camel-iconv.h> -#include <camel/camel-stream-filter.h> #include <camel/camel-mime-filter-charset.h> -#include <camel/camel-stream-mem.h> -#include <camel/camel-stream-fs.h> #include <camel/camel-mime-filter-tohtml.h> -#include <camel/camel-multipart-signed.h> #include <camel/camel-multipart-encrypted.h> +#include <camel/camel-multipart-signed.h> +#include <camel/camel-stream-filter.h> +#include <camel/camel-stream-fs.h> +#include <camel/camel-stream-mem.h> #include <camel/camel-string-utils.h> -#include <camel/camel-cipher-context.h> #if defined (HAVE_NSS) #include <camel/camel-smime-context.h> #endif #include "mail/em-utils.h" -#include "mail/em-composer-utils.h" -#include "mail/mail-config.h" -#include "mail/mail-crypto.h" #include "mail/mail-tools.h" -#include "mail/mail-ops.h" -#include "mail/mail-mt.h" -#include "mail/mail-session.h" -#include "mail/em-popup.h" -#include "mail/em-menu.h" #include "e-msg-composer.h" #include "e-attachment.h" @@ -101,8 +84,6 @@ #include "e-composer-private.h" #include "e-composer-header-table.h" -#include "evolution-shell-component-utils.h" - #ifdef HAVE_XFREE #include <X11/XF86keysym.h> #endif @@ -147,6 +128,7 @@ typedef enum { enum { SEND, SAVE_DRAFT, + PRINT, LAST_SIGNAL }; @@ -502,6 +484,7 @@ build_message (EMsgComposer *composer, CamelMultipart *body = NULL; CamelContentType *type; CamelMimeMessage *new; + CamelSession *session; CamelStream *stream; CamelMimePart *part; CamelException ex; @@ -521,6 +504,7 @@ build_message (EMsgComposer *composer, account = e_composer_header_table_get_account (table); view = e_msg_composer_get_attachment_view (composer); store = e_attachment_view_get_store (view); + session = e_msg_composer_get_session (composer); /* evil kludgy hack for Redirect */ if (p->redirect) { @@ -772,8 +756,14 @@ build_message (EMsgComposer *composer, if (pgp_sign) { CamelMimePart *npart = camel_mime_part_new (); - cipher = mail_crypto_get_pgp_cipher_context (account); - camel_cipher_sign (cipher, pgp_userid, CAMEL_CIPHER_HASH_SHA1, part, npart, &ex); + cipher = camel_gpg_context_new (session); + if (account != NULL) + camel_gpg_context_set_always_trust ( + CAMEL_GPG_CONTEXT (cipher), + account->pgp_always_trust); + camel_cipher_sign ( + cipher, pgp_userid, CAMEL_CIPHER_HASH_SHA1, + part, npart, &ex); camel_object_unref (cipher); if (camel_exception_is_set (&ex)) { @@ -792,8 +782,14 @@ build_message (EMsgComposer *composer, if (account && account->pgp_encrypt_to_self && pgp_userid) g_ptr_array_add (recipients, g_strdup (pgp_userid)); - cipher = mail_crypto_get_pgp_cipher_context (account); - camel_cipher_encrypt (cipher, pgp_userid, recipients, part, npart, &ex); + cipher = camel_gpg_context_new (session); + if (account != NULL) + camel_gpg_context_set_always_trust ( + CAMEL_GPG_CONTEXT (cipher), + account->pgp_always_trust); + camel_cipher_encrypt ( + cipher, pgp_userid, recipients, + part, npart, &ex); camel_object_unref (cipher); if (account && account->pgp_encrypt_to_self && pgp_userid) @@ -867,6 +863,7 @@ build_message (EMsgComposer *composer, } if (smime_encrypt) { + /* check to see if we should encrypt to self, NB removed after use */ if (account->smime_encrypt_to_self) g_ptr_array_add (recipients, g_strdup (account->smime_encrypt_key)); @@ -946,103 +943,6 @@ skip_content: /* Signatures */ static gchar * -get_file_content (EMsgComposer *composer, - const gchar *filename, - gboolean want_html, - guint flags, - gboolean warn) -{ - CamelStreamFilter *filtered_stream; - CamelStreamMem *memstream; - CamelMimeFilter *html, *charenc; - CamelStream *stream; - GByteArray *buffer; - gchar *charset; - gchar *content; - gint fd; - - fd = g_open (filename, O_RDONLY, 0); - if (fd == -1) { - if (warn) - e_error_run ((GtkWindow *)composer, "mail-composer:no-sig-file", - filename, g_strerror (errno), NULL); - return g_strdup (""); - } - - stream = camel_stream_fs_new_with_fd (fd); - - if (want_html) { - filtered_stream = camel_stream_filter_new_with_stream (stream); - camel_object_unref (stream); - - html = camel_mime_filter_tohtml_new (flags, 0); - camel_stream_filter_add (filtered_stream, html); - camel_object_unref (html); - - stream = (CamelStream *) filtered_stream; - } - - memstream = (CamelStreamMem *) camel_stream_mem_new (); - buffer = g_byte_array_new (); - camel_stream_mem_set_byte_array (memstream, buffer); - - camel_stream_write_to_stream (stream, (CamelStream *) memstream); - camel_object_unref (stream); - - /* The newer signature UI saves signatures in UTF-8, but we still need to check that - the signature is valid UTF-8 because it is possible that the user imported a - signature file that is in his/her locale charset. If it's not in UTF-8 and not in - the charset the composer is in (or their default mail charset) then - there's nothing we can do. */ - if (buffer->len && !g_utf8_validate ((const gchar *)buffer->data, buffer->len, NULL)) { - stream = (CamelStream *) memstream; - memstream = (CamelStreamMem *) camel_stream_mem_new (); - camel_stream_mem_set_byte_array (memstream, g_byte_array_new ()); - - filtered_stream = camel_stream_filter_new_with_stream (stream); - camel_object_unref (stream); - - charset = composer && composer->priv->charset ? composer->priv->charset : NULL; - charset = charset ? g_strdup (charset) : e_composer_get_default_charset (); - if ((charenc = (CamelMimeFilter *) camel_mime_filter_charset_new_convert (charset, "UTF-8"))) { - camel_stream_filter_add (filtered_stream, charenc); - camel_object_unref (charenc); - } - - g_free (charset); - - camel_stream_write_to_stream ((CamelStream *) filtered_stream, (CamelStream *) memstream); - camel_object_unref (filtered_stream); - g_byte_array_free (buffer, TRUE); - - buffer = memstream->buffer; - } - - camel_object_unref (memstream); - - g_byte_array_append (buffer, (const guint8 *)"", 1); - content = (char*)buffer->data; - g_byte_array_free (buffer, FALSE); - - return content; -} - -gchar * -e_msg_composer_get_sig_file_content (const gchar *sigfile, gboolean in_html) -{ - if (!sigfile || !*sigfile) { - return NULL; - } - - return get_file_content (NULL, sigfile, !in_html, - CAMEL_MIME_FILTER_TOHTML_PRESERVE_8BIT | - CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS | - CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES | - CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES, - FALSE); -} - -static gchar * encode_signature_name (const gchar *name) { const gchar *s; @@ -1132,34 +1032,6 @@ decode_signature_name (const gchar *name) return dname; } -static gboolean -add_signature_delim (void) -{ - gboolean res; - GConfClient *client = gconf_client_get_default (); - - res = !gconf_client_get_bool (client, COMPOSER_GCONF_NO_SIGNATURE_DELIM_KEY, NULL); - - g_object_unref (client); - - return res; -} - -static gboolean -is_top_signature (void) -{ - GConfClient *gconf; - gboolean res = FALSE; - - gconf = gconf_client_get_default (); - - res = gconf_client_get_bool (gconf, COMPOSER_GCONF_TOP_SIGNATURE_KEY, NULL); - - g_object_unref (gconf); - - return res; -} - #define CONVERT_SPACES CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES #define NO_SIGNATURE_TEXT \ "<!--+GtkHTML:<DATA class=\"ClueFlow\" key=\"signature\" value=\"1\">-->" \ @@ -1171,7 +1043,7 @@ get_signature_html (EMsgComposer *composer) EComposerHeaderTable *table; gchar *text = NULL, *html = NULL; ESignature *signature; - gboolean format_html, add_delim; + gboolean format_html; table = e_msg_composer_get_header_table (composer); signature = e_composer_header_table_get_signature (table); @@ -1179,19 +1051,18 @@ get_signature_html (EMsgComposer *composer) if (!signature) return NULL; - add_delim = add_signature_delim (); - if (!signature->autogen) { if (!signature->filename) return NULL; format_html = signature->html; - if (signature->script) { - text = mail_config_signature_run_script (signature->filename); - } else { - text = e_msg_composer_get_sig_file_content (signature->filename, format_html); - } + if (signature->script) + text = e_run_signature_script ( + signature->filename); + else + text = e_read_signature_file ( + signature, TRUE, NULL); } else { EAccount *account; EAccountIdentity *id; @@ -1208,8 +1079,7 @@ get_signature_html (EMsgComposer *composer) name = id->name ? camel_text_to_html (id->name, CONVERT_SPACES, 0) : NULL; organization = id->organization ? camel_text_to_html (id->organization, CONVERT_SPACES, 0) : NULL; - text = g_strdup_printf ("%s%s%s%s%s%s%s%s%s", - add_delim ? "-- <BR>" : "", + text = g_strdup_printf ("-- <BR>%s%s%s%s%s%s%s%s", name ? name : "", (address && *address) ? " <<A HREF=\"mailto:" : "", address ? address : "", @@ -1239,13 +1109,12 @@ get_signature_html (EMsgComposer *composer) "<!--+GtkHTML:<DATA class=\"ClueFlow\" key=\"signature_name\" value=\"uid:%s\">-->" "<TABLE WIDTH=\"100%%\" CELLSPACING=\"0\" CELLPADDING=\"0\"><TR><TD><BR>" "%s%s%s%s" - "%s</TD></TR></TABLE>", + "</TD></TR></TABLE>", encoded_uid ? encoded_uid : "", format_html ? "" : "<PRE>\n", - format_html || !add_delim || (!strncmp ("-- \n", text, 4) || strstr (text, "\n-- \n")) ? "" : "-- \n", + format_html || (!strncmp ("-- \n", text, 4) || strstr (text, "\n-- \n")) ? "" : "-- \n", text, - format_html ? "" : "</PRE>\n", - is_top_signature () ? "<BR>" : ""); + format_html ? "" : "</PRE>\n"); g_free (text); g_free (encoded_uid); text = html; @@ -1259,11 +1128,17 @@ set_editor_text (EMsgComposer *composer, const gchar *text, gboolean set_signature) { - gchar *body = NULL; + EShell *shell; + EShellSettings *shell_settings; + gboolean reply_signature_on_top; + gchar *body = NULL, *html = NULL; g_return_if_fail (E_IS_MSG_COMPOSER (composer)); g_return_if_fail (text != NULL); + shell = e_shell_get_default (); + shell_settings = e_shell_get_shell_settings (shell); + /* Keeping Signatures in the beginning of composer @@ -1278,9 +1153,30 @@ set_editor_text (EMsgComposer *composer, */ - if (is_top_signature ()) { - /* put marker to the top */ - body = g_strdup_printf ("<BR>" NO_SIGNATURE_TEXT "%s", text); + reply_signature_on_top = e_shell_settings_get_boolean ( + shell_settings, "composer-top-signature"); + + if (set_signature && reply_signature_on_top) { + gchar *tmp = NULL; + tmp = get_signature_html (composer); + if (tmp) { + /* Minimizing the damage. Make it just a part of the body instead of a signature */ + html = strstr (tmp, "-- \n"); + if (html) { + /* That two consecutive - symbols followed by a space */ + *(html+1) = ' '; + body = g_strdup_printf ("</br>%s</br>%s", tmp, text); + } else { + /* HTML Signature. Make it as part of body */ + body = g_strdup_printf ("</br>%s</br>%s", tmp, text); + } + g_free (tmp); + } else { + /* No signature set */ + body = g_strdup_printf ("<!--+GtkHTML:<DATA class=\"ClueFlow\" key=\"signature\" value=\"1\">-->" + "<!--+GtkHTML:<DATA class=\"ClueFlow\" key=\"signature_name\" value=\"uid:Noname\">-->" + "<TABLE WIDTH=\"100%%\" CELLSPACING=\"0\" CELLPADDING=\"0\"><TR><TD> </TD></TR></TABLE>%s", text); + } } else { /* no marker => to the bottom */ body = g_strdup_printf ("%s<BR>", text); @@ -1317,14 +1213,6 @@ autosave_load_draft (const gchar *filename) if (e_composer_autosave_snapshot (composer)) g_unlink (filename); - g_signal_connect ( - composer, "send", - G_CALLBACK (em_utils_composer_send_cb), NULL); - - g_signal_connect ( - composer, "save-draft", - G_CALLBACK (em_utils_composer_save_draft_cb), NULL); - gtk_widget_show (GTK_WIDGET (composer)); } @@ -1483,7 +1371,7 @@ msg_composer_account_changed_cb (EMsgComposer *composer) bcc_addrs = account->bcc_addrs; uid = account->id->sig_uid; - signature = uid ? mail_config_get_signature_by_uid (uid) : NULL; + signature = uid ? e_get_signature_by_uid (uid) : NULL; e_composer_header_table_set_signature (table, signature); /* XXX This should be done more generically. The composer @@ -1539,46 +1427,6 @@ msg_composer_account_list_changed_cb (EMsgComposer *composer) g_object_unref (iterator); } -static void -msg_composer_update_preferences (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - EMsgComposer *composer) -{ - GtkhtmlEditor *editor; - gboolean enable; - GError *error = NULL; - - editor = GTKHTML_EDITOR (composer); - - enable = gconf_client_get_bool ( - client, COMPOSER_GCONF_INLINE_SPELLING_KEY, &error); - if (error == NULL) - gtkhtml_editor_set_inline_spelling (editor, enable); - else { - g_warning ("%s", error->message); - g_clear_error (&error); - } - - enable = gconf_client_get_bool ( - client, COMPOSER_GCONF_MAGIC_LINKS_KEY, &error); - if (error == NULL) - gtkhtml_editor_set_magic_links (editor, enable); - else { - g_warning ("%s", error->message); - g_clear_error (&error); - } - - enable = gconf_client_get_bool ( - client, COMPOSER_GCONF_MAGIC_SMILEYS_KEY, &error); - if (error == NULL) - gtkhtml_editor_set_magic_smileys (editor, enable); - else { - g_warning ("%s", error->message); - g_clear_error (&error); - } -} - struct _drop_data { EMsgComposer *composer; @@ -1589,188 +1437,8 @@ struct _drop_data { guint32 action; guint info; guint time; - - unsigned int move:1; - unsigned int moved:1; - unsigned int aborted:1; }; -#if 0 /* FIXME */ -static void -drop_action (EMsgComposer *composer, - GdkDragContext *context, - guint32 action, - GtkSelectionData *selection, - guint info, - guint time, - gboolean html_dnd) -{ - char *tmp, *str, **urls; - CamelMimePart *mime_part; - CamelStream *stream; - CamelMimeMessage *msg; - char *content_type; - int i, success = FALSE, delete = FALSE; - EMsgComposerPrivate *p = composer->priv; - - switch (info) { - case DND_TYPE_MESSAGE_RFC822: - d (printf ("dropping a message/rfc822\n")); - /* write the message (s) out to a CamelStream so we can use it */ - stream = camel_stream_mem_new (); - camel_stream_write (stream, (const gchar *)selection->data, selection->length); - camel_stream_reset (stream); - - msg = camel_mime_message_new (); - if (camel_data_wrapper_construct_from_stream ((CamelDataWrapper *)msg, stream) != -1) { - msg_composer_attach_message (composer, msg); - success = TRUE; - delete = action == GDK_ACTION_MOVE; - } - - camel_object_unref (msg); - camel_object_unref (stream); - break; - case DND_TYPE_NETSCAPE_URL: - d (printf ("dropping a _NETSCAPE_URL\n")); - tmp = g_strndup ((const gchar *) selection->data, selection->length); - urls = g_strsplit (tmp, "\n", 2); - g_free (tmp); - - /* _NETSCAPE_URL is represented as "URI\nTITLE" */ - handle_uri (composer, urls[0], html_dnd); - - g_strfreev (urls); - success = TRUE; - break; - case DND_TYPE_TEXT_URI_LIST: - d (printf ("dropping a text/uri-list\n")); - tmp = g_strndup ((const gchar *) selection->data, selection->length); - urls = g_strsplit (tmp, "\n", 0); - g_free (tmp); - - for (i = 0; urls[i] != NULL; i++) { - str = g_strstrip (urls[i]); - if (str[0] == '#' || str[0] == '\0') - continue; - - handle_uri (composer, str, html_dnd); - } - - g_strfreev (urls); - success = TRUE; - break; - case DND_TYPE_TEXT_VCARD: - case DND_TYPE_TEXT_CALENDAR: - content_type = gdk_atom_name (selection->type); - d (printf ("dropping a %s\n", content_type)); - - mime_part = camel_mime_part_new (); - camel_mime_part_set_content (mime_part, (const gchar *)selection->data, selection->length, content_type); - camel_mime_part_set_disposition (mime_part, "inline"); - - e_attachment_bar_attach_mime_part (E_ATTACHMENT_BAR (p->attachment_bar), mime_part); - - camel_object_unref (mime_part); - g_free (content_type); - - success = TRUE; - break; - case DND_TYPE_X_UID_LIST: { - GPtrArray *uids; - char *inptr, *inend; - CamelFolder *folder; - CamelException ex = CAMEL_EXCEPTION_INITIALISER; - - /* NB: This all runs synchronously, could be very slow/hang/block the ui */ - - uids = g_ptr_array_new (); - - inptr = (char*)selection->data; - inend = (char*)(selection->data + selection->length); - while (inptr < inend) { - char *start = inptr; - - while (inptr < inend && *inptr) - inptr++; - - if (start > (char *)selection->data) - g_ptr_array_add (uids, g_strndup (start, inptr-start)); - - inptr++; - } - - if (uids->len > 0) { - folder = mail_tool_uri_to_folder ((const gchar *)selection->data, 0, &ex); - if (folder) { - if (uids->len == 1) { - msg = camel_folder_get_message (folder, uids->pdata[0], &ex); - if (msg == NULL) - goto fail; - msg_composer_attach_message (composer, msg); - } else { - CamelMultipart *mp = camel_multipart_new (); - char *desc; - - camel_data_wrapper_set_mime_type ((CamelDataWrapper *)mp, "multipart/digest"); - camel_multipart_set_boundary (mp, NULL); - for (i=0;i<uids->len;i++) { - msg = camel_folder_get_message (folder, uids->pdata[i], &ex); - if (msg) { - mime_part = camel_mime_part_new (); - camel_mime_part_set_disposition (mime_part, "inline"); - camel_medium_set_content_object ((CamelMedium *)mime_part, (CamelDataWrapper *)msg); - camel_mime_part_set_content_type (mime_part, "message/rfc822"); - camel_multipart_add_part (mp, mime_part); - camel_object_unref (mime_part); - camel_object_unref (msg); - } else { - camel_object_unref (mp); - goto fail; - } - } - mime_part = camel_mime_part_new (); - camel_medium_set_content_object ((CamelMedium *)mime_part, (CamelDataWrapper *)mp); - /* translators, this count will always be >1 */ - desc = g_strdup_printf (ngettext ("Attached message", "%d attached messages", uids->len), uids->len); - camel_mime_part_set_description (mime_part, desc); - g_free (desc); - e_attachment_bar_attach_mime_part (E_ATTACHMENT_BAR(p->attachment_bar), mime_part); - camel_object_unref (mime_part); - camel_object_unref (mp); - } - success = TRUE; - delete = action == GDK_ACTION_MOVE; - fail: - if (camel_exception_is_set (&ex)) { - char *name; - - camel_object_get (folder, NULL, CAMEL_FOLDER_NAME, &name, NULL); - e_error_run ((GtkWindow *)composer, "mail-composer:attach-nomessages", - name?name:(char *)selection->data, camel_exception_get_description (&ex), NULL); - camel_object_free (folder, CAMEL_FOLDER_NAME, name); - } - camel_object_unref (folder); - } else { - e_error_run ((GtkWindow *)composer, "mail-composer:attach-nomessages", - (const gchar*)selection->data, camel_exception_get_description (&ex), NULL); - } - - camel_exception_clear (&ex); - } - - g_ptr_array_free (uids, TRUE); - - break; } - default: - d (printf ("dropping an unknown\n")); - break; - } - - gtk_drag_finish (context, success, delete, time); -} -#endif - static void msg_composer_notify_header_cb (EMsgComposer *composer) { @@ -1785,11 +1453,11 @@ msg_composer_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { + EShell *shell; + EShellSettings *shell_settings; GObject *object; EMsgComposer *composer; GtkToggleAction *action; - GList *spell_languages; - GConfClient *client; GArray *array; gboolean active; guint binding_id; @@ -1799,9 +1467,11 @@ msg_composer_constructor (GType type, type, n_construct_properties, construct_properties); composer = E_MSG_COMPOSER (object); - client = gconf_client_get_default (); array = composer->priv->gconf_bridge_binding_ids; + shell = e_shell_get_default (); + shell_settings = e_shell_get_shell_settings (shell); + /* Restore Persistent State */ binding_id = gconf_bridge_bind_property ( @@ -1848,29 +1518,16 @@ msg_composer_constructor (GType type, /* Honor User Preferences */ - active = gconf_client_get_bool ( - client, COMPOSER_GCONF_SEND_HTML_KEY, NULL); + active = e_shell_settings_get_boolean ( + shell_settings, "composer-format-html"); gtkhtml_editor_set_html_mode (GTKHTML_EDITOR (composer), active); action = GTK_TOGGLE_ACTION (ACTION (REQUEST_READ_RECEIPT)); - active = gconf_client_get_bool ( - client, COMPOSER_GCONF_REQUEST_RECEIPT_KEY, NULL); + active = e_shell_settings_get_boolean ( + shell_settings, "composer-request-receipt"); gtk_toggle_action_set_active (action, active); - spell_languages = e_load_spell_languages (); - gtkhtml_editor_set_spell_languages ( - GTKHTML_EDITOR (composer), spell_languages); - g_list_free (spell_languages); - - gconf_client_add_dir ( - client, COMPOSER_GCONF_PREFIX, - GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); - composer->priv->notify_id = gconf_client_notify_add ( - client, COMPOSER_GCONF_PREFIX, (GConfClientNotifyFunc) - msg_composer_update_preferences, composer, NULL, NULL); - msg_composer_update_preferences (client, 0, NULL, composer); - - g_object_unref (client); + e_shell_watch_window (shell, GTK_WINDOW (object)); return object; } @@ -1917,15 +1574,6 @@ msg_composer_destroy (GtkObject *object) composer->priv->address_dialog = NULL; } - if (composer->priv->notify_id) { - GConfClient *client; - - client = gconf_client_get_default (); - gconf_client_notify_remove (client, composer->priv->notify_id); - composer->priv->notify_id = 0; - g_object_unref (client); - } - /* Chain up to parent's destroy() method. */ GTK_OBJECT_CLASS (parent_class)->destroy (object); } @@ -2133,7 +1781,7 @@ msg_composer_paste_clipboard (GtkhtmlEditor *editor) clipboard = gtk_widget_get_clipboard (widget, GDK_SELECTION_CLIPBOARD); /* Assume the clipboard has an image. The return - * value will be NULL we we assumed wrong. */ + * value will be NULL if we assumed wrong. */ pixbuf = gtk_clipboard_wait_for_image (clipboard); if (!GDK_IS_PIXBUF (pixbuf)) goto chainup; @@ -2444,7 +2092,7 @@ msg_composer_class_init (EMsgComposerClass *class) signals[SEND] = g_signal_new ( "send", - E_TYPE_MSG_COMPOSER, + G_OBJECT_CLASS_TYPE (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, @@ -2452,11 +2100,20 @@ msg_composer_class_init (EMsgComposerClass *class) signals[SAVE_DRAFT] = g_signal_new ( "save-draft", - E_TYPE_MSG_COMPOSER, + G_OBJECT_CLASS_TYPE (class), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + + signals[PRINT] = g_signal_new ( + "print", + G_OBJECT_CLASS_TYPE (class), + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__ENUM, + G_TYPE_NONE, 1, + GTK_TYPE_PRINT_OPERATION_ACTION); } static void @@ -2471,6 +2128,7 @@ msg_composer_init (EMsgComposer *composer) GtkUIManager *ui_manager; GtkhtmlEditor *editor; GtkHTML *html; + const gchar *id; gint n_targets; composer->priv = E_MSG_COMPOSER_GET_PRIVATE (composer); @@ -2507,9 +2165,9 @@ msg_composer_init (EMsgComposer *composer) /* Configure Headers */ e_composer_header_table_set_account_list ( - table, mail_config_get_accounts ()); + table, e_get_account_list ()); e_composer_header_table_set_signature_list ( - table, mail_config_get_signatures ()); + table, e_get_signature_list ()); g_signal_connect_swapped ( table, "notify::account", @@ -2559,8 +2217,9 @@ msg_composer_init (EMsgComposer *composer) /* Initialization may have tripped the "changed" state. */ gtkhtml_editor_set_changed (editor, FALSE); - e_plugin_ui_register_manager ( - "org.gnome.evolution.composer", ui_manager, composer); + id = "org.gnome.evolution.composer"; + e_plugin_ui_register_manager (ui_manager, id, composer); + e_plugin_ui_enable_manager (ui_manager, id); } GType @@ -2636,6 +2295,7 @@ create_composer (gint visible_mask) /** * e_msg_composer_new_with_type: + * @type: the type of composer to create * * Create a new message composer widget. The type can be * E_MSG_COMPOSER_MAIL, E_MSG_COMPOSER_POST or E_MSG_COMPOSER_MAIL_POST. @@ -2644,7 +2304,7 @@ create_composer (gint visible_mask) **/ EMsgComposer * -e_msg_composer_new_with_type (int type) +e_msg_composer_new_with_type (gint type) { EMsgComposer *composer; gint visible_mask; @@ -2685,6 +2345,24 @@ e_msg_composer_new (void) return e_msg_composer_new_with_type (E_MSG_COMPOSER_MAIL); } +static gboolean +is_special_header (const gchar *hdr_name) +{ + /* Note: a header is a "special header" if it has any meaning: + 1. it's not a X-* header or + 2. it's an X-Evolution* header + */ + if (g_ascii_strncasecmp (hdr_name, "X-", 2)) + return TRUE; + + if (!g_ascii_strncasecmp (hdr_name, "X-Evolution", 11)) + return TRUE; + + /* we can keep all other X-* headers */ + + return FALSE; +} + static void e_msg_composer_set_pending_body (EMsgComposer *composer, gchar *text, @@ -2875,6 +2553,7 @@ handle_multipart_encrypted (EMsgComposer *composer, CamelCipherContext *cipher; CamelDataWrapper *content; CamelMimePart *mime_part; + CamelSession *session; CamelException ex; CamelCipherValidity *valid; GtkToggleAction *action; @@ -2884,7 +2563,8 @@ handle_multipart_encrypted (EMsgComposer *composer, gtk_toggle_action_set_active (action, TRUE); camel_exception_init (&ex); - cipher = mail_crypto_get_pgp_cipher_context (NULL); + session = e_msg_composer_get_session (composer); + cipher = camel_gpg_context_new (session); mime_part = camel_mime_part_new (); valid = camel_cipher_decrypt (cipher, multipart, mime_part, &ex); camel_object_unref (cipher); @@ -3069,11 +2749,11 @@ set_signature_gui (EMsgComposer *composer) data = gtkhtml_editor_get_paragraph_data (editor, "signature_name"); if (g_str_has_prefix (data, "uid:")) { decoded = decode_signature_name (data + 4); - signature = mail_config_get_signature_by_uid (decoded); + signature = e_get_signature_by_uid (decoded); g_free (decoded); } else if (g_str_has_prefix (data, "name:")) { decoded = decode_signature_name (data + 5); - signature = mail_config_get_signature_by_name (decoded); + signature = e_get_signature_by_name (decoded); g_free (decoded); } @@ -3142,10 +2822,12 @@ e_msg_composer_new_with_message (CamelMimeMessage *message) account_name = g_strdup (account_name); g_strstrip (account_name); - if ((account = mail_config_get_account_by_uid (account_name)) == NULL) - /* 'old' setting */ - account = mail_config_get_account_by_name (account_name); - if (account) { + account = e_get_account_by_uid (account_name); + if (account == NULL) + /* XXX Backwards compatibility */ + account = e_get_account_by_name (account_name); + + if (account != NULL) { g_free (account_name); account_name = g_strdup (account->name); } @@ -3328,8 +3010,9 @@ e_msg_composer_new_with_message (CamelMimeMessage *message) /* set extra headers */ headers = CAMEL_MIME_PART (message)->headers; while (headers) { - if (g_ascii_strcasecmp (headers->name, "References") == 0 || - g_ascii_strcasecmp (headers->name, "In-Reply-To") == 0) { + if (!is_special_header (headers->name) || + !g_ascii_strcasecmp (headers->name, "References") || + !g_ascii_strcasecmp (headers->name, "In-Reply-To")) { g_ptr_array_add (p->extra_hdr_names, g_strdup (headers->name)); g_ptr_array_add (p->extra_hdr_values, g_strdup (headers->value)); } @@ -3435,6 +3118,35 @@ e_msg_composer_new_redirect (CamelMimeMessage *message, } /** + * e_msg_composer_get_session: + * @composer: an #EMsgComposer + * + * Returns the mail module's global #CamelSession instance. Calling + * this function will load the mail module if it isn't already loaded. + * + * Returns: the mail module's #CamelSession + **/ +CamelSession * +e_msg_composer_get_session (EMsgComposer *composer) +{ + EShell *shell; + EShellSettings *shell_settings; + CamelSession *session; + + /* FIXME EMsgComposer should own a reference to EShell. */ + + g_return_val_if_fail (E_IS_MSG_COMPOSER (composer), NULL); + + shell = e_shell_get_default (); + shell_settings = e_shell_get_shell_settings (shell); + + session = e_shell_settings_get_pointer (shell_settings, "mail-session"); + g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL); + + return session; +} + +/** * e_msg_composer_send: * @composer: an #EMsgComposer * @@ -3470,6 +3182,22 @@ e_msg_composer_save_draft (EMsgComposer *composer) e_composer_autosave_set_saved (composer, FALSE); } +/** + * e_msg_composer_print: + * @composer: an #EMsgComposer + * @action: the print action to start + * + * Print the message in @composer. + **/ +void +e_msg_composer_print (EMsgComposer *composer, + GtkPrintOperationAction action) +{ + g_return_if_fail (E_IS_MSG_COMPOSER (composer)); + + g_signal_emit (composer, signals[PRINT], 0, action); +} + static GList * add_recipients (GList *list, const gchar *recips) { @@ -4133,7 +3861,6 @@ e_msg_composer_show_sig_file (EMsgComposer *composer) GtkhtmlEditor *editor; GtkHTML *html; gchar *html_text; - gboolean top_signature; g_return_if_fail (E_IS_MSG_COMPOSER (composer)); @@ -4160,8 +3887,6 @@ e_msg_composer_show_sig_file (EMsgComposer *composer) } gtkhtml_editor_run_command (editor, "unblock-selection"); - top_signature = is_top_signature (); - html_text = get_signature_html (composer); if (html_text) { gtkhtml_editor_run_command (editor, "insert-paragraph"); @@ -4175,10 +3900,6 @@ e_msg_composer_show_sig_file (EMsgComposer *composer) gtkhtml_editor_run_command (editor, "style-normal"); gtkhtml_editor_insert_html (editor, html_text); g_free (html_text); - } else if (top_signature) { - /* insert paragraph after the signature ClueFlow things */ - gtkhtml_editor_run_command (editor, "cursor-forward"); - gtkhtml_editor_run_command (editor, "insert-paragraph"); } gtkhtml_editor_undo_end (editor); @@ -4320,17 +4041,8 @@ e_msg_composer_load_from_file (const gchar *filename) camel_object_unref (stream); composer = e_msg_composer_new_with_message (msg); - if (composer != NULL) { - g_signal_connect ( - composer, "send", - G_CALLBACK (em_utils_composer_send_cb), NULL); - - g_signal_connect ( - composer, "save-draft", - G_CALLBACK (em_utils_composer_save_draft_cb), NULL); - + if (composer != NULL) gtk_widget_show (GTK_WIDGET (composer)); - } return composer; } |