* email could now be sent without patching the source as the from address is stored in gconf
pmo-trunk-r112
ModestTnyTransportActions *actions;
ModestUIPrivate *priv;
GtkWidget *to_entry, *subject_entry, *body_view;
- const gchar *to, *subject;
+ const gchar *to, *subject, *email_from;
gchar *body;
GtkTextIter start, end;
GtkTextBuffer *buf;
TnyAccountStoreIface *account_store;
const GList *transport_accounts;
TnyTransportAccountIface *transport_account;
+ ModestConf *conf;
+ ModestAccountMgr *acc_mgr;
g_return_if_fail (modest_ui);
gtk_text_buffer_get_bounds (buf, &start, &end);
body = gtk_text_buffer_get_text (buf, &start, &end, FALSE);
- g_message ("sending %s ==> %s", subject, to);
+ /* FIXME: HACK! */
+ conf = MODEST_CONF(modest_conf_new());
+ acc_mgr = MODEST_ACCOUNT_MGR(modest_account_mgr_new (conf));
+ if (!acc_mgr) {
+ g_warning ("failed to instantiate account mgr");
+ return;
+ }
+ email_from = modest_account_mgr_get_identity_string(acc_mgr, "myidentity", MODEST_ACCOUNT_EMAIL, NULL);
+ /* end HACK */
+
+ g_message("sending \"%s\" %s ==> %s", subject, email_from, to);
modest_tny_transport_actions_send_message (actions,
transport_account,
- "dirk-jan.binnema@nokia.com",
+ email_from,
to, "", "", subject,
body);
g_free (body);
#include "modest-conf-keys.h"
-#define MODEST_CONF_DEFAULT_ACCOUNT "/default_account"
+#define MODEST_CONF_DEFAULT_ACCOUNT "/default_account"
-#define MODEST_SERVER_ACCOUNT_NAMESPACE MODEST_CONF_NAMESPACE "/" "server_accounts"
-
/* configuration key definitions for modest */
-#define MODEST_ACCOUNT_NAMESPACE MODEST_CONF_NAMESPACE "/" "accounts"
+#define MODEST_ACCOUNT_NAMESPACE MODEST_CONF_NAMESPACE "/" "accounts"
+#define MODEST_SERVER_ACCOUNT_NAMESPACE MODEST_CONF_NAMESPACE "/" "server_accounts"
+#define MODEST_IDENTITY_NAMESPACE MODEST_CONF_NAMESPACE "/" "identities"
/* per-account data */
-#define MODEST_ACCOUNT_DISPLAY_NAME "display_name" /* string */
-#define MODEST_ACCOUNT_STORE_ACCOUNT "store_account" /* string */
-#define MODEST_ACCOUNT_TRANSPORT_ACCOUNT "transport_account" /* string */
+#define MODEST_ACCOUNT_DISPLAY_NAME "display_name" /* string */
+#define MODEST_ACCOUNT_STORE_ACCOUNT "store_account" /* string */
+#define MODEST_ACCOUNT_TRANSPORT_ACCOUNT "transport_account" /* string */
/* server account keys */
-#define MODEST_ACCOUNT_PASSWORD "password" /* string */
-#define MODEST_ACCOUNT_HOSTNAME "hostname" /* string */
-#define MODEST_ACCOUNT_USERNAME "username" /* string */
-#define MODEST_ACCOUNT_PROTO "proto" /* string */
-
-
-#define MODEST_ACCOUNT_LEAVE_ON_SERVER "leave_on_server" /* boolean */ \
-#define MODEST_ACCOUNT_PREFERRED_CNX "preferred_cnx" /* string */
+#define MODEST_ACCOUNT_PASSWORD "password" /* string */
+#define MODEST_ACCOUNT_HOSTNAME "hostname" /* string */
+#define MODEST_ACCOUNT_USERNAME "username" /* string */
+#define MODEST_ACCOUNT_PROTO "proto" /* string */
+
+#define MODEST_ACCOUNT_LEAVE_ON_SERVER "leave_on_server" /* boolean */
+#define MODEST_ACCOUNT_PREFERRED_CNX "preferred_cnx" /* string */
+
+/* user identity keys */
+#define MODEST_ACCOUNT_EMAIL "email" /* string */
+#define MODEST_ACCOUNT_REPLYTO "replyto" /* string */
+#define MODEST_ACCOUNT_SIGNATURE "signature" /* string */
+#define MODEST_ACCOUNT_USE_SIGNATURE "use_signature" /* boolean */
+#define MODEST_ACCOUNT_ID_VIA "id_via" /* string */
+#define MODEST_ACCOUNT_USE_ID_VIA "use_id_via" /* boolean */
+/* MISSING: everything related to gpg */
#endif /*__MODEST_CONF_KEYS_H__*/
static gchar* get_account_keyname (const gchar *accname, const gchar *name);
static gchar* get_server_account_keyname (const gchar *accname, const gchar *name);
+static gchar* get_identity_keyname (const gchar *accname, const gchar *name);
/* list my signals */
enum {
null_means_empty(proto),
NULL);
g_free (key);
-
+ g_free (acckey);
+
return TRUE; /* FIXME: better error checking */
}
return retval;
}
+gboolean
+modest_account_mgr_remove_identity (ModestAccountMgr *self,
+ const gchar *name,
+ GError **err)
+{
+ ModestAccountMgrPrivate *priv;
+ gchar *acckey, *key;
+ gboolean retval;
+
+ g_return_val_if_fail (self, FALSE);
+ g_return_val_if_fail (name, FALSE);
+
+ priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
+
+ acckey = g_strconcat (MODEST_IDENTITY_NAMESPACE, "/",
+ name, NULL);
+
+ if (!modest_conf_key_exists(priv->modest_conf, acckey, NULL)) {
+ g_warning ("server account %s does not exist exist", name);
+ g_free (acckey);
+ return FALSE;
+ }
+
+ retval = modest_conf_remove_key (priv->modest_conf, acckey, NULL);
+ g_free (acckey);
+
+ return retval;
+}
+
+
+
+gboolean
+modest_account_mgr_add_identity (ModestAccountMgr *self,
+ const gchar *name,
+ const gchar *email,
+ const gchar *replyto,
+ const gchar *signature,
+ const gboolean use_signature,
+ const gchar *id_via,
+ const gboolean use_id_via)
+{
+ ModestAccountMgrPrivate *priv;
+ gchar *id_key, *key;
+
+ g_return_val_if_fail (self, FALSE);
+ g_return_val_if_fail (name, FALSE);
+
+ /* TODO: check already exists */
+
+ priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
+ id_key = g_strconcat (MODEST_IDENTITY_NAMESPACE, "/",
+ name, NULL);
+
+ if (modest_conf_key_exists(priv->modest_conf, id_key, NULL)) {
+ g_warning ("identity %s already exists", name);
+ g_free (id_key);
+ return FALSE;
+ }
+
+ /* email */
+ key = g_strconcat (id_key, "/", MODEST_ACCOUNT_EMAIL, NULL);
+ modest_conf_set_string (priv->modest_conf, key,
+ null_means_empty(email), NULL);
+ g_free (key);
+
+ /* replyto */
+ key = g_strconcat (id_key, "/", MODEST_ACCOUNT_REPLYTO, NULL);
+ modest_conf_set_string (priv->modest_conf, key,
+ null_means_empty(replyto), NULL);
+ g_free (key);
+
+ /* signature */
+ key = g_strconcat (id_key, "/", MODEST_ACCOUNT_SIGNATURE, NULL);
+ modest_conf_set_string (priv->modest_conf, key,
+ null_means_empty(signature), NULL);
+ g_free (key);
+
+ /* use_signature */
+ key = g_strconcat (id_key, "/", MODEST_ACCOUNT_USE_SIGNATURE, NULL);
+ modest_conf_set_bool (priv->modest_conf, key,
+ use_signature, NULL);
+ g_free (key);
+
+ /* signature */
+ key = g_strconcat (id_key, "/", MODEST_ACCOUNT_ID_VIA, NULL);
+ modest_conf_set_string (priv->modest_conf, key,
+ null_means_empty(id_via), NULL);
+ g_free (key);
+
+ /* use_signature */
+ key = g_strconcat (id_key, "/", MODEST_ACCOUNT_USE_ID_VIA, NULL);
+ modest_conf_set_bool (priv->modest_conf, key,
+ use_id_via, NULL);
+ g_free (key);
+ g_free (id_key);
+
+ return TRUE; /* FIXME: better error checking */
+}
/* strip the first /n/ character from each element */
/* caller must make sure all elements are strings with
return get_account_string (self, name, key, FALSE, err);
}
+gchar*
+modest_account_mgr_get_identity_string (ModestAccountMgr *self, const gchar *name,
+ const gchar *key, GError **err)
+{
+ ModestAccountMgrPrivate *priv;
+
+ gchar *keyname;
+ gchar * retval;
+
+ g_return_val_if_fail (self, NULL);
+ g_return_val_if_fail (name, NULL);
+ g_return_val_if_fail (key, NULL);
+
+ keyname = get_identity_keyname (name, key);
+
+ priv = MODEST_ACCOUNT_MGR_GET_PRIVATE(self);
+ retval = modest_conf_get_string (priv->modest_conf,keyname,err);
+ g_free (keyname);
+
+ return retval;
+}
static gint
}
-
gboolean
modest_account_mgr_account_exists (ModestAccountMgr *self, const gchar *name,
GError **err)
return account_exists (self, name, FALSE, err);
}
+gboolean
+modest_account_mgr_identity_exists (ModestAccountMgr *self, const gchar *name,
+ GError **err)
+{
+ return account_exists (self, name, TRUE, err);
+}
+
/* must be freed by caller */
(MODEST_SERVER_ACCOUNT_NAMESPACE, "/",
accname, NULL);
}
+
+/* must be freed by caller */
+static gchar*
+get_identity_keyname (const gchar *accname, const gchar *name)
+{
+ if (name)
+ return g_strconcat
+ (MODEST_IDENTITY_NAMESPACE "/",
+ accname, "/", name, NULL);
+ else
+ return g_strconcat
+ (MODEST_IDENTITY_NAMESPACE, "/",
+ accname, NULL);
+}
/**
* modest_account_mgr_add_server_account:
* @self: a ModestAccountMgr instance
+ * @name: name (id) of the account
* @hostname: the hostname
* @username: the username
* @password: the password
- * @proto: the prototype
- * @err: a GError ptr, or NULL to ignore.
+ * @proto: the protocol (imap, smtp, ...) used for this account
*
- * add a server account to the configuration
+ * add a server account to the configuration.
* the server account with @name should not already exist
- *
- * Returns: TRUE if succeeded, FALSE otherwise,
- * @err gives details in case of error
+ *
+ * Returns: TRUE if succeeded, FALSE otherwise,
*/
gboolean modest_account_mgr_add_server_account (ModestAccountMgr *self,
const gchar *name,
gboolean modest_account_mgr_remove_server_account (ModestAccountMgr *self,
const gchar *name,
GError **err);
+ /**
+ * modest_account_mgr_remove_identity:
+ * @self: a ModestAccountMgr instance
+ * @name: the name for the identity
+ * @err: a GError ptr, or NULL to ignore.
+ *
+ * remove aidentity from the configuration
+ * the identity with @name should exist
+ *
+ * Returns: TRUE if the removal succeeded, FALSE otherwise,
+ * @err gives details in case of error
+ */
+gboolean modest_account_mgr_remove_identity (ModestAccountMgr *self,
+ const gchar *name,
+ GError **err);
+
+/**
+ * modest_account_mgr_add_identity:
+ * @self: a ModestAccountMgr instance
+ * @name: the name (id) for the identity
+ * @email: the user's email address
+ * @replyto: default replyto address
+ * @signature: the signature for this identity
+ * @use_signature: whether to use this signature instead of the default one
+ * @id_via: the transport to send emails for this identity via
+ * @use_id_via: whether to use this via insteda of the default one
+ *
+ * add a user identity to the configuration
+ *
+ * Returns: TRUE if succeeded, FALSE otherwise,
+ */
+gboolean
+modest_account_mgr_add_identity (ModestAccountMgr *self,
+ const gchar *name,
+ const gchar *email,
+ const gchar *replyto,
+ const gchar *signature,
+ const gboolean use_signature,
+ const gchar *id_via,
+ const gboolean use_id_via);
/**
* modest_account_mgr_account_names:
gchar* modest_account_mgr_get_server_account_string (ModestAccountMgr *self,
const gchar *name,
const gchar *key, GError **err);
+gchar* modest_account_mgr_get_identity_string (ModestAccountMgr *self,
+ const gchar *name,
+ const gchar *key, GError **err);
/**
G_END_DECLS
#endif /* __MODEST_ACCOUNT_MGR_H__ */
-
NULL, "imap");
modest_account_mgr_add_server_account (acc_mgr, "mytransport", "localhost", NULL,
NULL, "smtp");
+
}
+ if (modest_account_mgr_identity_exists(acc_mgr, "myidentity", NULL)) {
+ if (!modest_account_mgr_remove_identity(acc_mgr, "myidentity", NULL)) {
+ g_warning ("could not delete existing identity");
+ }
+ }
+ if (!modest_account_mgr_add_identity (acc_mgr, "myidentity", "user@localhost",
+ "", "", FALSE, NULL, FALSE ))
+ g_warning ("failed to add test account");
g_object_unref (G_OBJECT(acc_mgr));
}
-