aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog17
-rw-r--r--mail/em-composer-utils.c148
-rw-r--r--mail/em-composer-utils.h2
-rw-r--r--mail/em-folder-tree.c2
-rw-r--r--mail/em-folder-utils.c2
-rw-r--r--mail/em-folder-view.c3
-rw-r--r--mail/em-utils.c46
-rw-r--r--mail/em-utils.h1
-rw-r--r--mail/mail-component.c1
-rw-r--r--mail/mail-component.h1
10 files changed, 216 insertions, 7 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 7a1af5aab8..cf9dbffc54 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,20 @@
+2008-07-20 Bharath Acharya <abharath@novell.com>
+
+ ** Fix for bug #200147
+ Added basic Template support
+
+ * em-composer-utils.c (edit_message), (em_utils_edit_message): Modified
+ to suit it better for plugins to use it. And added support for template
+ placeholders to be replaced in the messages.
+ * em-composer-utils.h:
+ * em-folder-tree.c (is_special_local_folder):
+ * em-folder-utils.c (emfu_is_special_local_folder):
+ * em-folder-view.c (em_folder_view_open_selected):
+ * em-utils.c (em_utils_folder_is_templates):
+ * em-utils.h:
+ * mail-component.c:
+ * mail-component.h:
+
2008-07-16 Sankar P <psankar@novell.com>
Pushing disk summary changes from the madagascar branch
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index 257d66c486..fa517f8dd5 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -68,6 +68,8 @@
#define gmtime_r(tp,tmp) (gmtime(tp)?(*(tmp)=*gmtime(tp),(tmp)):0)
#endif
+#define GCONF_KEY_TEMPLATE_PLACEHOLDERS "/apps/evolution/mail/template_placeholders"
+
static EAccount * guess_account (CamelMimeMessage *message, CamelFolder *folder);
struct emcs_t {
@@ -808,8 +810,144 @@ edit_message (CamelMimeMessage *message, CamelFolder *drafts, const char *uid)
{
EMsgComposer *composer;
+ /* Template specific code follows. */
+ if (em_utils_folder_is_templates(drafts, NULL) == TRUE) {
+ /* retrieve the message from the CamelFolder */
+ CamelDataWrapper *content;
+ CamelStream *mem;
+ CamelContentType *type;
+ CamelMimePart *mime_part = CAMEL_MIME_PART (message);
+ CamelDataWrapper *mail_text;
+ CamelMultipart *body = camel_multipart_new ();
+ CamelStream *stream;
+ CamelMimePart *part;
+ int count1 = 0, string_changed = 0;
+
+ char *str, *convert_str = NULL;
+ gsize bytes_read, bytes_written;
+ gint count = 2;
+
+ content = camel_medium_get_content_object ((CamelMedium *) message);
+ if (!content)
+ return;
+
+ /*
+ * Get non-multipart content from multipart message.
+ */
+ while (CAMEL_IS_MULTIPART (content) && count > 0)
+ {
+ mime_part = camel_multipart_get_part (CAMEL_MULTIPART (content), 0);
+ content = camel_medium_get_content_object (CAMEL_MEDIUM (mime_part));
+ count--;
+ }
+
+ if (!mime_part)
+ return;
+
+ type = camel_mime_part_get_content_type (mime_part);
+ if (!camel_content_type_is (type, "text", "plain"))
+ return;
+
+ mem = camel_stream_mem_new ();
+ camel_data_wrapper_decode_to_stream (content, mem);
+
+ str = g_strndup ((const gchar*)((CamelStreamMem *) mem)->buffer->data, ((CamelStreamMem *) mem)->buffer->len);
+ camel_object_unref (mem);
+
+ const char *cur = str;
+ int i;
+ for (i = 0; i < strlen(str); i++) {
+ if (!g_ascii_strncasecmp (cur, "$", 1)) {
+ const char *end = cur, *check_env;
+ char *out;
+ GConfClient *gconf;
+ GSList *clue_list = NULL, *list;
+
+ gconf = gconf_client_get_default ();
+
+ while (*end && !isspace (*end) && (*end != '"'))
+ end++;
+
+ out = g_strndup ((const gchar *) cur, end - cur);
+ check_env = out;
+
+ char **temp_str = g_strsplit (str, out, 2);
+
+ /* Get the list from gconf */
+ clue_list = gconf_client_get_list ( gconf, GCONF_KEY_TEMPLATE_PLACEHOLDERS, GCONF_VALUE_STRING, NULL );
+
+ g_object_unref (gconf);
+
+ for (list = clue_list; list; list = g_slist_next (list)) {
+ char **temp = g_strsplit (list->data, "=", 2);
+ if (!g_ascii_strcasecmp(temp[0], out+1)) {
+ str = g_strdup_printf("%s%s%s", temp_str[0], temp[1], temp_str[1]);
+ cur = str + i;
+ count1 = 1;
+ string_changed = 1;
+ }
+ else
+ count1 = 0;
+ g_strfreev(temp);
+ }
+
+ if (clue_list) {
+ g_slist_foreach (clue_list, (GFunc) g_free, NULL);
+ g_slist_free (clue_list);
+ }
+
+ if (!count1) {
+ if (getenv(out+1)) {
+ str = g_strdup_printf("%s%s%s", temp_str[0], getenv(out + 1), temp_str[1]);
+ cur = str + i;
+ count1 = 1;
+ string_changed = 1;
+ }
+ else
+ count1 = 0;
+ }
+
+ g_strfreev(temp_str);
+ }
+ else
+ cur++;
+ }
+
+ if (string_changed) {
+
+ /* Create toplevel container */
+ camel_data_wrapper_set_mime_type (CAMEL_DATA_WRAPPER (body),
+ "multipart/alternative;");
+ camel_multipart_set_boundary (body, NULL);
+
+ stream = camel_stream_mem_new ();
+
+ mail_text = camel_data_wrapper_new ();
+ camel_data_wrapper_set_mime_type_field (mail_text, type);
+
+ camel_stream_printf (stream, "%s", g_strdup(str));
+
+ camel_data_wrapper_construct_from_stream (mail_text, stream);
+ camel_object_unref (stream);
+
+ part = camel_mime_part_new ();
+ camel_medium_set_content_object (CAMEL_MEDIUM (part), mail_text);
+ camel_object_unref (mail_text);
+ camel_multipart_add_part (body, part);
+ camel_object_unref (part);
+
+ /* Finish creating the message */
+ camel_medium_set_content_object (CAMEL_MEDIUM (message), CAMEL_DATA_WRAPPER(body));
+ camel_object_unref (body);
+ }
+ }
+
composer = e_msg_composer_new_with_message (message);
- em_composer_utils_setup_callbacks (composer, NULL, NULL, 0, 0, drafts, uid);
+
+ if (em_utils_folder_is_templates(drafts, NULL) == TRUE)
+ em_composer_utils_setup_callbacks (composer, NULL, NULL, 0, 0, NULL, NULL);
+ else
+ em_composer_utils_setup_callbacks (composer, NULL, NULL, 0, 0, drafts, uid);
composer_set_no_change (composer, TRUE);
@@ -819,16 +957,20 @@ edit_message (CamelMimeMessage *message, CamelFolder *drafts, const char *uid)
/**
* em_utils_edit_message:
* @message: message to edit
+ * @folder: used to recognize the templates folder
*
* Opens a composer filled in with the headers/mime-parts/etc of
* @message.
**/
void
-em_utils_edit_message (CamelMimeMessage *message)
+em_utils_edit_message (CamelMimeMessage *message, CamelFolder *folder)
{
g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));
- edit_message (message, NULL, NULL);
+ if (folder)
+ edit_message (message, folder, NULL);
+ else
+ edit_message (message, NULL, NULL);
}
static void
diff --git a/mail/em-composer-utils.h b/mail/em-composer-utils.h
index 147fb41049..cee813fc8f 100644
--- a/mail/em-composer-utils.h
+++ b/mail/em-composer-utils.h
@@ -51,7 +51,7 @@ void em_utils_compose_new_message_with_mailto (const char *url, const char *from
void em_utils_post_to_folder (struct _CamelFolder *folder);
void em_utils_post_to_url (const char *url);
-void em_utils_edit_message (struct _CamelMimeMessage *message);
+void em_utils_edit_message (struct _CamelMimeMessage *message, struct _CamelFolder *folder);
void em_utils_edit_messages (struct _CamelFolder *folder, GPtrArray *uids, gboolean replace);
void em_utils_forward_attached (struct _CamelFolder *folder, GPtrArray *uids, const char *fromuri);
diff --git a/mail/em-folder-tree.c b/mail/em-folder-tree.c
index ea108daad6..3d2175a22a 100644
--- a/mail/em-folder-tree.c
+++ b/mail/em-folder-tree.c
@@ -1087,7 +1087,7 @@ tree_drag_data_received(GtkWidget *widget, GdkDragContext *context, int x, int y
static gboolean
is_special_local_folder (const char *name)
{
- return (!strcmp (name, "Drafts") || !strcmp (name, "Inbox") || !strcmp (name, "Outbox") || !strcmp (name, "Sent"));
+ return (!strcmp (name, "Drafts") || !strcmp (name, "Inbox") || !strcmp (name, "Outbox") || !strcmp (name, "Sent") || !strcmp (name, "Templates"));
}
static GdkAtom
diff --git a/mail/em-folder-utils.c b/mail/em-folder-utils.c
index aae43e2441..551d14bcec 100644
--- a/mail/em-folder-utils.c
+++ b/mail/em-folder-utils.c
@@ -81,7 +81,7 @@ extern CamelSession *session;
static gboolean
emfu_is_special_local_folder (const char *name)
{
- return (!strcmp (name, "Drafts") || !strcmp (name, "Inbox") || !strcmp (name, "Outbox") || !strcmp (name, "Sent"));
+ return (!strcmp (name, "Drafts") || !strcmp (name, "Inbox") || !strcmp (name, "Outbox") || !strcmp (name, "Sent") || !strcmp (name, "Templates"));
}
struct _EMCopyFolders {
diff --git a/mail/em-folder-view.c b/mail/em-folder-view.c
index b7f911ad9d..3dad22a1a3 100644
--- a/mail/em-folder-view.c
+++ b/mail/em-folder-view.c
@@ -520,6 +520,7 @@ em_folder_view_open_selected(EMFolderView *emfv)
}
if (em_utils_folder_is_drafts(emfv->folder, emfv->folder_uri)
+ || em_utils_folder_is_templates(emfv->folder, emfv->folder_uri)
|| em_utils_folder_is_outbox(emfv->folder, emfv->folder_uri)) {
em_utils_edit_messages(emfv->folder, uids, TRUE);
return uids->len;
@@ -2647,7 +2648,7 @@ emfv_list_double_click(ETree *tree, gint row, ETreePath path, gint col, GdkEvent
/* Ignore double-clicks on columns that handle thier own state */
if (MESSAGE_LIST_COLUMN_IS_ACTIVE (col))
return;
-
+
em_folder_view_open_selected(emfv);
}
diff --git a/mail/em-utils.c b/mail/em-utils.c
index ff686f3d8c..4fd8a98958 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -1364,7 +1364,53 @@ em_utils_temp_save_part(GtkWidget *parent, CamelMimePart *part, gboolean mode)
return path;
}
+/** em_utils_folder_is_templates:
+ * @folder: folder
+ * @uri: uri for this folder, if known
+ *
+ * Decides if @folder is a Templates folder.
+ *
+ * Returns %TRUE if this is a Drafts folder or %FALSE otherwise.
+ **/
+
+gboolean
+em_utils_folder_is_templates (CamelFolder *folder, const char *uri)
+{
+ EAccountList *accounts;
+ EAccount *account;
+ EIterator *iter;
+ int is = FALSE;
+ char *templates_uri;
+ if (folder == mail_component_get_folder (NULL, MAIL_COMPONENT_FOLDER_TEMPLATES))
+ return TRUE;
+
+ if (uri == NULL)
+ return FALSE;
+
+ accounts = mail_config_get_accounts();
+ iter = e_list_get_iterator ((EList *)accounts);
+ while (e_iterator_is_valid (iter)) {
+ account = (EAccount *)e_iterator_get (iter);
+
+ if (account->templates_folder_uri) {
+ templates_uri = em_uri_to_camel (account->templates_folder_uri);
+ if (camel_store_folder_uri_equal (folder->parent_store, templates_uri, uri)) {
+ g_free (templates_uri);
+ is = TRUE;
+ break;
+ }
+ g_free (templates_uri);
+ }
+
+ e_iterator_next (iter);
+ }
+
+ g_object_unref (iter);
+
+ return is;
+}
+
/**
* em_utils_folder_is_drafts:
* @folder: folder
diff --git a/mail/em-utils.h b/mail/em-utils.h
index 045b922e3d..5fd05faafb 100644
--- a/mail/em-utils.h
+++ b/mail/em-utils.h
@@ -82,6 +82,7 @@ char *em_utils_temp_save_part(struct _GtkWidget *parent, struct _CamelMimePart *
void em_utils_save_parts (struct _GtkWidget *parent, const char *prompt, GSList * parts);
gboolean em_utils_folder_is_drafts(struct _CamelFolder *folder, const char *uri);
+gboolean em_utils_folder_is_templates(struct _CamelFolder *folder, const char *uri);
gboolean em_utils_folder_is_sent(struct _CamelFolder *folder, const char *uri);
gboolean em_utils_folder_is_outbox(struct _CamelFolder *folder, const char *uri);
diff --git a/mail/mail-component.c b/mail/mail-component.c
index 18c489b7ae..c4b0e317ad 100644
--- a/mail/mail-component.c
+++ b/mail/mail-component.c
@@ -161,6 +161,7 @@ static struct {
{ N_("Drafts"), },
{ N_("Outbox"), },
{ N_("Sent"), },
+ { N_("Templates"), },
{ "Inbox", }, /* 'always local' inbox */
};
diff --git a/mail/mail-component.h b/mail/mail-component.h
index 0a418d2238..9e775ad59f 100644
--- a/mail/mail-component.h
+++ b/mail/mail-component.h
@@ -47,6 +47,7 @@ enum _mail_component_folder_t {
MAIL_COMPONENT_FOLDER_DRAFTS,
MAIL_COMPONENT_FOLDER_OUTBOX,
MAIL_COMPONENT_FOLDER_SENT,
+ MAIL_COMPONENT_FOLDER_TEMPLATES,
MAIL_COMPONENT_FOLDER_LOCAL_INBOX,
};