Commit 3449e5fc authored by Matthew Barnes's avatar Matthew Barnes

Adapt mail to the new ESource API.

parent f78795f4
......@@ -22,6 +22,7 @@ libemail_engine_la_CPPFLAGS = \
libmailengineincludedir = $(privincludedir)/libemail-engine
libmailengineinclude_HEADERS = \
camel-null-store.h \
e-mail-authenticator.h \
e-mail-enums.h \
e-mail-enumtypes.h \
e-mail-folder-utils.h \
......@@ -40,6 +41,7 @@ libmailengineinclude_HEADERS = \
libemail_engine_la_SOURCES = \
$(libmailengineinclude_HEADERS) \
camel-null-store.c \
e-mail-authenticator.c \
e-mail-enumtypes.c \
e-mail-folder-utils.c \
e-mail-junk-filter.c \
......
/*
* e-mail-authenticator.c
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
*/
#include "e-mail-authenticator.h"
#include <config.h>
#include <glib/gi18n-lib.h>
#define E_MAIL_AUTHENTICATOR_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), E_TYPE_MAIL_AUTHENTICATOR, EMailAuthenticatorPrivate))
struct _EMailAuthenticatorPrivate {
CamelService *service;
gchar *mechanism;
};
enum {
PROP_0,
PROP_MECHANISM,
PROP_SERVICE
};
/* Forward Declarations */
static void e_mail_authenticator_interface_init
(ESourceAuthenticatorInterface *interface);
G_DEFINE_TYPE_WITH_CODE (
EMailAuthenticator,
e_mail_authenticator,
G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (
E_TYPE_SOURCE_AUTHENTICATOR,
e_mail_authenticator_interface_init))
static void
mail_authenticator_set_mechanism (EMailAuthenticator *auth,
const gchar *mechanism)
{
g_return_if_fail (auth->priv->mechanism == NULL);
auth->priv->mechanism = g_strdup (mechanism);
}
static void
mail_authenticator_set_service (EMailAuthenticator *auth,
CamelService *service)
{
g_return_if_fail (CAMEL_IS_SERVICE (service));
g_return_if_fail (auth->priv->service == NULL);
auth->priv->service = g_object_ref (service);
}
static void
mail_authenticator_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_MECHANISM:
mail_authenticator_set_mechanism (
E_MAIL_AUTHENTICATOR (object),
g_value_get_string (value));
return;
case PROP_SERVICE:
mail_authenticator_set_service (
E_MAIL_AUTHENTICATOR (object),
g_value_get_object (value));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
mail_authenticator_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_MECHANISM:
g_value_set_string (
value,
e_mail_authenticator_get_mechanism (
E_MAIL_AUTHENTICATOR (object)));
return;
case PROP_SERVICE:
g_value_set_object (
value,
e_mail_authenticator_get_service (
E_MAIL_AUTHENTICATOR (object)));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
mail_authenticator_dispose (GObject *object)
{
EMailAuthenticatorPrivate *priv;
priv = E_MAIL_AUTHENTICATOR_GET_PRIVATE (object);
if (priv->service != NULL) {
g_object_unref (priv->service);
priv->service = NULL;
}
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (e_mail_authenticator_parent_class)->dispose (object);
}
static void
mail_authenticator_finalize (GObject *object)
{
EMailAuthenticatorPrivate *priv;
priv = E_MAIL_AUTHENTICATOR_GET_PRIVATE (object);
g_free (priv->mechanism);
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (e_mail_authenticator_parent_class)->finalize (object);
}
static ESourceAuthenticationResult
mail_authenticator_try_password_sync (ESourceAuthenticator *auth,
const GString *password,
GCancellable *cancellable,
GError **error)
{
CamelService *service;
EMailAuthenticator *mail_auth;
CamelAuthenticationResult camel_result;
ESourceAuthenticationResult source_result;
const gchar *mechanism;
mail_auth = E_MAIL_AUTHENTICATOR (auth);
service = e_mail_authenticator_get_service (mail_auth);
mechanism = e_mail_authenticator_get_mechanism (mail_auth);
camel_service_set_password (service, password->str);
camel_result = camel_service_authenticate_sync (
service, mechanism, cancellable, error);
switch (camel_result) {
case CAMEL_AUTHENTICATION_ERROR:
source_result = E_SOURCE_AUTHENTICATION_ERROR;
break;
case CAMEL_AUTHENTICATION_ACCEPTED:
source_result = E_SOURCE_AUTHENTICATION_ACCEPTED;
break;
case CAMEL_AUTHENTICATION_REJECTED:
source_result = E_SOURCE_AUTHENTICATION_REJECTED;
break;
default:
g_set_error (
error, CAMEL_SERVICE_ERROR,
CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
_("Invalid authentication result code (%d)"),
camel_result);
source_result = E_SOURCE_AUTHENTICATION_ERROR;
break;
}
return source_result;
}
static void
e_mail_authenticator_class_init (EMailAuthenticatorClass *class)
{
GObjectClass *object_class;
g_type_class_add_private (class, sizeof (EMailAuthenticatorPrivate));
object_class = G_OBJECT_CLASS (class);
object_class->set_property = mail_authenticator_set_property;
object_class->get_property = mail_authenticator_get_property;
object_class->dispose = mail_authenticator_dispose;
object_class->finalize = mail_authenticator_finalize;
g_object_class_install_property (
object_class,
PROP_MECHANISM,
g_param_spec_string (
"mechanism",
"Mechanism",
"Authentication mechanism",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (
object_class,
PROP_SERVICE,
g_param_spec_object (
"service",
"Service",
"The CamelService to authenticate",
CAMEL_TYPE_SERVICE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
}
static void
e_mail_authenticator_interface_init (ESourceAuthenticatorInterface *interface)
{
interface->try_password_sync = mail_authenticator_try_password_sync;
}
static void
e_mail_authenticator_init (EMailAuthenticator *auth)
{
auth->priv = E_MAIL_AUTHENTICATOR_GET_PRIVATE (auth);
}
ESourceAuthenticator *
e_mail_authenticator_new (CamelService *service,
const gchar *mechanism)
{
g_return_val_if_fail (CAMEL_IS_SERVICE (service), NULL);
return g_object_new (
E_TYPE_MAIL_AUTHENTICATOR,
"service", service, "mechanism", mechanism, NULL);
}
CamelService *
e_mail_authenticator_get_service (EMailAuthenticator *auth)
{
g_return_val_if_fail (E_IS_MAIL_AUTHENTICATOR (auth), NULL);
return auth->priv->service;
}
const gchar *
e_mail_authenticator_get_mechanism (EMailAuthenticator *auth)
{
g_return_val_if_fail (E_IS_MAIL_AUTHENTICATOR (auth), NULL);
return auth->priv->mechanism;
}
/*
* e-mail-authenticator.h
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
*/
#ifndef E_MAIL_AUTHENTICATOR_H
#define E_MAIL_AUTHENTICATOR_H
#include <camel/camel.h>
#include <libedataserver/e-source-authenticator.h>
/* Standard GObject macros */
#define E_TYPE_MAIL_AUTHENTICATOR \
(e_mail_authenticator_get_type ())
#define E_MAIL_AUTHENTICATOR(obj) \
(G_TYPE_CHECK_INSTANCE_CAST \
((obj), E_TYPE_MAIL_AUTHENTICATOR, EMailAuthenticator))
#define E_MAIL_AUTHENTICATOR_CLASS(cls) \
(G_TYPE_CHECK_CLASS_CAST \
((cls), E_TYPE_MAIL_AUTHENTICATOR, EMailAuthenticatorClass))
#define E_IS_MAIL_AUTHENTICATOR(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE \
((obj), E_TYPE_MAIL_AUTHENTICATOR))
#define E_IS_MAIL_AUTHENTICATOR_CLASS(cls) \
(G_TYPE_CHECK_CLASS_TYPE \
((cls), E_TYPE_MAIL_AUTHENTICATOR))
#define E_MAIL_AUTHENTICATOR_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS \
((obj), E_TYPE_MAIL_AUTHENTICATOR, EMailAuthenticatorClass))
G_BEGIN_DECLS
typedef struct _EMailAuthenticator EMailAuthenticator;
typedef struct _EMailAuthenticatorClass EMailAuthenticatorClass;
typedef struct _EMailAuthenticatorPrivate EMailAuthenticatorPrivate;
/**
* EMailAuthenticator:
*
* Contains only private data that should be read and manipulated using the
* functions below.
**/
struct _EMailAuthenticator {
GObject parent;
EMailAuthenticatorPrivate *priv;
};
struct _EMailAuthenticatorClass {
GObjectClass parent_class;
};
GType e_mail_authenticator_get_type (void);
ESourceAuthenticator *
e_mail_authenticator_new (CamelService *service,
const gchar *mechanism);
CamelService * e_mail_authenticator_get_service
(EMailAuthenticator *auth);
const gchar * e_mail_authenticator_get_mechanism
(EMailAuthenticator *auth);
G_END_DECLS
#endif /* E_MAIL_AUTHENTICATOR_H */
......@@ -23,11 +23,11 @@
#include "e-mail-session-utils.h"
#include <glib/gi18n-lib.h>
#include <libedataserver/e-source-mail-submission.h>
#include <libemail-engine/e-mail-folder-utils.h>
#include <libemail-engine/e-mail-utils.h>
#include <libemail-engine/mail-tools.h>
#include <libemail-utils/e-account-utils.h>
/* X-Mailer header value */
#define X_MAILER ("Evolution " VERSION SUB_VERSION " " VERSION_COMMENT)
......@@ -671,7 +671,8 @@ e_mail_session_send_to (EMailSession *session,
CamelAddress *recipients;
CamelMedium *medium;
CamelMessageInfo *info;
EAccount *account = NULL;
ESourceRegistry *registry;
ESource *source = NULL;
GPtrArray *post_to_uris;
struct _camel_header_raw *xev;
struct _camel_header_raw *header;
......@@ -684,6 +685,8 @@ e_mail_session_send_to (EMailSession *session,
g_return_if_fail (E_IS_MAIL_SESSION (session));
g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));
registry = e_mail_session_get_registry (session);
medium = CAMEL_MEDIUM (message);
camel_medium_set_header (medium, "X-Mailer", X_MAILER);
......@@ -692,28 +695,27 @@ e_mail_session_send_to (EMailSession *session,
/* Extract directives from X-Evolution headers. */
string = camel_header_raw_find (&xev, "X-Evolution-Account", NULL);
string = camel_header_raw_find (&xev, "X-Evolution-Identity", NULL);
if (string != NULL) {
gchar *account_uid;
account_uid = g_strstrip (g_strdup (string));
account = e_get_account_by_uid (account_uid);
g_free (account_uid);
gchar *uid = g_strstrip (g_strdup (string));
source = e_source_registry_ref_source (registry, uid);
g_free (uid);
}
if (account != NULL) {
if (account->transport != NULL) {
if (E_IS_SOURCE (source)) {
ESourceMailSubmission *extension;
const gchar *extension_name;
/* XXX Transport UIDs are kludgy right now. We
* use the EAccount's regular UID and tack on
* "-transport". Will be better soon. */
transport_uid = g_strconcat (
account->uid, "-transport", NULL);
extension_name = E_SOURCE_EXTENSION_MAIL_SUBMISSION;
extension = e_source_get_extension (source, extension_name);
/* to reprompt password on sending if needed */
account->transport->get_password_canceled = FALSE;
}
sent_folder_uri = g_strdup (account->sent_folder_uri);
string = e_source_mail_submission_get_sent_folder (extension);
sent_folder_uri = g_strdup (string);
string = e_source_mail_submission_get_transport_uid (extension);
transport_uid = g_strdup (string);
g_object_unref (source);
}
string = camel_header_raw_find (&xev, "X-Evolution-Fcc", NULL);
......
This diff is collapsed.
......@@ -26,6 +26,7 @@
#define E_MAIL_SESSION_H
#include <camel/camel.h>
#include <libedataserver/e-source-registry.h>
#include <libemail-engine/e-mail-enums.h>
#include <libemail-engine/mail-folder-cache.h>
#include <libemail-utils/em-vfolder-context.h>
......@@ -67,12 +68,22 @@ struct _EMailSession {
struct _EMailSessionClass {
CamelSessionClass parent_class;
EMVFolderContext * (*create_vfolder_context) (EMailSession *session);
EMVFolderContext *
(*create_vfolder_context)
(EMailSession *session);
void (*flush_outbox) (EMailSession *session);
void (*refresh_service) (EMailSession *session,
CamelService *service);
void (*store_added) (EMailSession *session,
CamelStore *store);
void (*store_removed) (EMailSession *session,
CamelStore *store);
};
GType e_mail_session_get_type (void);
EMailSession * e_mail_session_new (void);
EMailSession * e_mail_session_new (ESourceRegistry *registry);
ESourceRegistry *
e_mail_session_get_registry (EMailSession *session);
MailFolderCache *
e_mail_session_get_folder_cache (EMailSession *session);
CamelStore * e_mail_session_get_local_store (EMailSession *session);
......@@ -131,6 +142,19 @@ CamelFolder * e_mail_session_uri_to_folder_finish
EMVFolderContext *
e_mail_session_create_vfolder_context
(EMailSession *session);
/* Useful GBinding transform functions */
gboolean e_binding_transform_service_to_source
(GBinding *binding,
const GValue *source_value,
GValue *target_value,
gpointer session);
gboolean e_binding_transform_source_to_service
(GBinding *binding,
const GValue *source_value,
GValue *target_value,
gpointer session);
/*** Legacy API ***/
void mail_session_flush_filter_log (EMailSession *session);
......
This diff is collapsed.
......@@ -23,21 +23,39 @@
#define E_MAIL_UTILS_H
#include <camel/camel.h>
#include <libedataserver/e-account.h>
#include <libedataserver/e-source-registry.h>
gboolean em_utils_folder_is_drafts (CamelFolder *folder);
gboolean em_utils_folder_is_templates (CamelFolder *folder);
gboolean em_utils_folder_is_sent (CamelFolder *folder);
gboolean em_utils_folder_is_outbox (CamelFolder *folder);
gboolean em_utils_in_addressbook (CamelInternetAddress *addr,
gboolean em_utils_folder_is_drafts (ESourceRegistry *registry,
CamelFolder *folder);
gboolean em_utils_folder_is_templates (ESourceRegistry *registry,
CamelFolder *folder);
gboolean em_utils_folder_is_sent (ESourceRegistry *registry,
CamelFolder *folder);
gboolean em_utils_folder_is_outbox (ESourceRegistry *registry,
CamelFolder *folder);
gboolean em_utils_in_addressbook (ESourceRegistry *registry,
CamelInternetAddress *addr,
gboolean local_only);
CamelMimePart * em_utils_contact_photo (CamelInternetAddress *addr,
CamelMimePart * em_utils_contact_photo (ESourceRegistry *registry,
CamelInternetAddress *addr,
gboolean local);
EAccount * em_utils_guess_account (CamelMimeMessage *message,
ESource * em_utils_guess_mail_account (ESourceRegistry *registry,
CamelMimeMessage *message,
CamelFolder *folder);
ESource * em_utils_guess_mail_identity (ESourceRegistry *registry,
CamelMimeMessage *message,
CamelFolder *folder);
ESource * em_utils_guess_mail_account_with_recipients
(ESourceRegistry *registry,
CamelMimeMessage *message,
CamelFolder *folder);
EAccount * em_utils_guess_account_with_recipients
(CamelMimeMessage *message,
ESource * em_utils_guess_mail_identity_with_recipients
(ESourceRegistry *registry,
CamelMimeMessage *message,
CamelFolder *folder);
ESource * em_utils_ref_mail_identity_for_store
(ESourceRegistry *registry,
CamelStore *store);
void emu_remove_from_mail_cache (const GSList *addresses);
void emu_remove_from_mail_cache_1 (const gchar *address);
void emu_free_mail_cache (void);
......
......@@ -31,9 +31,6 @@
#include <libedataserver/e-data-server-util.h>
#include <libemail-utils/e-account-utils.h>
#include <libemail-utils/e-signature-utils.h>
#include "e-mail-folder-utils.h"
#include "mail-config.h"
#include "mail-tools.h"
......@@ -137,24 +134,6 @@ settings_int_value_changed (GSettings *settings,
*save_location = g_settings_get_int (settings, key);
}
void
mail_config_write (void)
{
EAccountList *account_list;
ESignatureList *signature_list;
if (!config)
return;
account_list = e_get_account_list ();
signature_list = e_get_signature_list ();
e_account_list_save (account_list);
e_signature_list_save (signature_list);
g_settings_sync ();
}
gint
mail_config_get_address_count (void)
{
......
......@@ -29,7 +29,6 @@ G_BEGIN_DECLS
/* Configuration */
void mail_config_init (EMailSession *session);
void mail_config_write (void);
/* General Accessor functions */
......
......@@ -341,11 +341,16 @@ update_1folder (MailFolderCache *cache,
const gchar *msg_subject,
CamelFolderInfo *info)
{
EMailSession *session;
ESourceRegistry *registry;
struct _folder_update *up;
CamelFolder *folder;
gint unread = -1;
gint deleted;
session = mail_folder_cache_get_session (cache);
registry = e_mail_session_get_registry (session);
folder = mfi->folder;
if (folder) {
gboolean folder_is_sent;
......@@ -354,9 +359,9 @@ update_1folder (MailFolderCache *cache,
gboolean folder_is_vtrash;
gboolean special_case;
folder_is_sent = em_utils_folder_is_sent (folder);
folder_is_drafts = em_utils_folder_is_drafts (folder);
folder_is_outbox = em_utils_folder_is_outbox (folder);
folder_is_sent = em_utils_folder_is_sent (registry, folder);
folder_is_drafts = em_utils_folder_is_drafts (registry, folder);
folder_is_outbox = em_utils_folder_is_outbox (registry, folder);
folder_is_vtrash = CAMEL_IS_VTRASH_FOLDER (folder);
special_case =
......
......@@ -35,8 +35,9 @@
#include <glib/gi18n.h>
#include <libedataserver/e-data-server-util.h>
#include <libedataserver/e-source-mail-account.h>
#include <libedataserver/e-source-mail-submission.h>
#include <libemail-utils/e-account-utils.h>
#include <libemail-utils/mail-mt.h>
#include "e-mail-utils.h"
......@@ -222,12 +223,20 @@ fetch_mail_exec (struct _fetch_mail_msg *m,
GError **error)
{
struct _filter_mail_msg *fm = (struct _filter_mail_msg *) m;
GObjectClass *class;
CamelFolder *folder = NULL;
CamelService *service;
CamelSession *session;
CamelSettings *settings;
CamelStore *parent_store;
CamelUIDCache *cache = NULL;
CamelURL *url;
gboolean keep;
gboolean delete_fetched;
gboolean is_local_delivery = FALSE;
const gchar *uid = NULL;
const gchar *data_dir;
gchar *cachename;
gint i;
service = CAMEL_SERVICE (m->store);
......@@ -239,6 +248,18 @@ fetch_mail_exec (struct _fetch_mail_msg *m,
goto exit;
g_object_ref (fm->destination);
service = CAMEL_SERVICE (m->store);
uid = camel_service_get_uid (service);
settings = camel_service_get_settings (service);
/* XXX This is a POP3-specific setting. */
class = G_OBJECT_GET_CLASS (settings);
if (g_object_class_find_property (class, "keep-on-server") != NULL)
g_object_get (settings, "keep-on-server", &keep, NULL);
/* Just for readability. */
delete_fetched = !keep;
url = camel_service_new_camel_url (service);
is_local_delivery = em_utils_is_local_delivery_mbox_file (url);
......@@ -276,32 +297,26 @@ fetch_mail_exec (struct _fetch_mail_msg *m,
camel_url_free (url);
if (folder != NULL) {
/* This handles 'keep on server' stuff, if we have any new
* uid's to copy across, we need to copy them to a new array
* 'cause of the way fetch_mail_free works. */
CamelUIDCache *cache = NULL;
CamelStore *parent_store;
CamelService *service;
const gchar *data_dir;
gchar *cachename;
if (folder == NULL)
goto exit;
parent_store = camel_folder_get_parent_store (folder);
parent_store = camel_folder_get_parent_store (folder);
if (m->fetch_count > 0) {
/* We probably should fetch some old messages first. */
m->still_more = camel_folder_fetch_messages_sync (folder, m->fetch_type,
m->fetch_count, cancellable, error) ? 1 : 0;
}
service = CAMEL_SERVICE (parent_store);
data_dir = camel_service_get_user_data_dir (service);
if (m->fetch_count > 0) {
/* We probably should fetch some old messages first. */
m->still_more = camel_folder_fetch_messages_sync (folder, m->fetch_type,
m->fetch_count, cancellable, error) ? 1 : 0;
}
service = CAMEL_SERVICE (parent_store);
data_dir = camel_service_get_user_data_dir (service);
cachename = g_build_filename (data_dir, "uid-cache", NULL);
cache = camel_uid_cache_new (cachename);
g_free (cachename);
cachename = g_build_filename (data_dir, "uid-cache", NULL);
cache = camel_uid_cache_new (cachename);