aboutsummaryrefslogtreecommitdiffstats
path: root/mail/mail-vfolder.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@HelixCode.com>2000-07-31 23:07:49 +0800
committerMichael Zucci <zucchi@src.gnome.org>2000-07-31 23:07:49 +0800
commit72092414aa9b150b03b69b26e216d2d057110f92 (patch)
tree7689661ce4288047e4bac43dc84d610a044eeacd /mail/mail-vfolder.c
parent9ddabfee03542411d02851a1b1f144707ce32b82 (diff)
downloadgsoc2013-evolution-72092414aa9b150b03b69b26e216d2d057110f92.tar.gz
gsoc2013-evolution-72092414aa9b150b03b69b26e216d2d057110f92.tar.zst
gsoc2013-evolution-72092414aa9b150b03b69b26e216d2d057110f92.zip
Configurable vfolder sources, and a button to save a search
as a new vfolder. 2000-07-31 Not Zed <NotZed@HelixCode.com> * mail-vfolder.h: Header for vfolder functions. * folder-browser.c (mail_uri_to_folder): Use new scheme to open vfolders. (search_save): New button/function to save a search as a vfolder. * mail-vfolder.c (vfolder_edit): Made asynchronous. (vfolder_uri_to_folder): New function for loading vfolders and setting up their source folders. (vfolder_refresh): Change shell vfolder uri's to indirect references rather than the real vfolder uri. (vfolder_gui_add_rule): Add a rule with user confirmation. (vfolder_create_part): Get a new part by name, for creating rules in code. * message-thread.c (thread_messages): Check for uid lookup failure, which indicates an error in the folder or calling code. svn path=/trunk/; revision=4422
Diffstat (limited to 'mail/mail-vfolder.c')
-rw-r--r--mail/mail-vfolder.c152
1 files changed, 141 insertions, 11 deletions
diff --git a/mail/mail-vfolder.c b/mail/mail-vfolder.c
index cef814082a..cd613040b1 100644
--- a/mail/mail-vfolder.c
+++ b/mail/mail-vfolder.c
@@ -18,11 +18,16 @@
#include "evolution-shell-component.h"
#include "folder-browser.h"
+#include "mail-vfolder.h"
+
+#include "camel/camel.h"
#include "filter/vfolder-context.h"
-#include "filter/filter-rule.h"
+#include "filter/vfolder-rule.h"
#include "filter/vfolder-editor.h"
+#define d(x) x
+
struct _vfolder_info {
char *name;
char *query;
@@ -35,10 +40,13 @@ static EvolutionStorage *vfolder_storage;
/* GROSS HACK: for passing to other parts of the program */
EvolutionShellClient *global_shell_client = NULL;
+
+/* more globals ... */
extern char *evolution_dir;
+extern CamelSession *session;
static struct _vfolder_info *
-vfolder_find(char *name)
+vfolder_find(const char *name)
{
GList *l = available_vfolders;
struct _vfolder_info *info;
@@ -74,11 +82,12 @@ vfolder_refresh(void)
/* check if the rule has changed ... otherwise, leave it */
if (strcmp(expr->str, info->query)) {
- printf("Must reconfigure vfolder with new rule?\n");
+ d(printf("Must reconfigure vfolder with new rule?\n"));
g_free(info->query);
info->query = g_strdup(expr->str);
- uri = g_strdup_printf("vfolder:%s/vfolder/%s?%s", evolution_dir, info->name, info->query);
+ /*uri = g_strdup_printf("vfolder:%s/vfolder/%s?%s", evolution_dir, info->name, info->query);*/
+ uri = g_strdup_printf("vfolder:%s", info->name);
path = g_strdup_printf("/%s", info->name);
evolution_storage_removed_folder(vfolder_storage, path);
evolution_storage_new_folder (vfolder_storage, path,
@@ -92,9 +101,10 @@ vfolder_refresh(void)
info = g_malloc(sizeof(*info));
info->name = g_strdup(rule->name);
info->query = g_strdup(expr->str);
- printf("Adding new vfolder: %s %s\n", rule->name, expr->str);
+ d(printf("Adding new vfolder: %s %s\n", rule->name, expr->str));
- uri = g_strdup_printf("vfolder:%s/vfolder/%s?%s", evolution_dir, info->name, info->query);
+ /*uri = g_strdup_printf("vfolder:%s/vfolder/%s?%s", evolution_dir, info->name, info->query);*/
+ uri = g_strdup_printf("vfolder:%s", info->name);
path = g_strdup_printf("/%s", info->name);
evolution_storage_new_folder (vfolder_storage, path,
"mail",
@@ -109,7 +119,7 @@ vfolder_refresh(void)
l = available_vfolders;
while (l) {
info = l->data;
- printf("removing vfolders %s %s\n", info->name, info->query);
+ d(printf("removing vfolders %s %s\n", info->name, info->query));
path = g_strdup_printf("/%s", info->name);
evolution_storage_removed_folder(vfolder_storage, path);
g_free(path);
@@ -160,17 +170,137 @@ vfolder_create_storage(EvolutionShellComponent *shell_component)
vfolder_refresh();
}
+/* maps the shell's uri to the real vfolder uri and open the folder */
+CamelFolder *
+vfolder_uri_to_folder(const char *uri)
+{
+ CamelFolder *mail_uri_to_folder(const char *);
+ void camel_vee_folder_add_folder(CamelFolder *, CamelFolder *);
+
+ struct _vfolder_info *info;
+ char *storeuri, *foldername;
+ VfolderRule *rule;
+ CamelStore *store = NULL;
+ CamelFolder *folder = NULL, *sourcefolder;
+ CamelException *ex;
+ const char *sourceuri;
+ int sources;
+
+ if (strncmp (uri, "vfolder:", 8))
+ return NULL;
+
+ info = vfolder_find(uri+8);
+ if (info == NULL) {
+ g_warning("Shell trying to open unknown vFolder: %s", uri);
+ return NULL;
+ }
+
+ d(printf("Opening vfolder: %s\n", uri));
+
+ rule = (VfolderRule *)rule_context_find_rule((RuleContext *)context, info->name);
+
+ storeuri = g_strdup_printf("vfolder:%s/vfolder/%s", evolution_dir, info->name);
+ foldername = g_strdup_printf("mbox?%s", info->query);
+ ex = camel_exception_new ();
+ store = camel_session_get_store (session, storeuri, ex);
+ if (store == NULL)
+ goto cleanup;
+
+ folder = camel_store_get_folder (store, foldername, TRUE, ex);
+ if (folder == NULL)
+ goto cleanup;
+
+ sourceuri = NULL;
+ sources = 0;
+ while ( (sourceuri = vfolder_rule_next_source(rule, sourceuri)) ) {
+ d(printf("adding vfolder source: %s\n", sourceuri));
+ sourcefolder = mail_uri_to_folder(sourceuri);
+ if (sourcefolder) {
+ sources++;
+ camel_vee_folder_add_folder(folder, sourcefolder);
+ }
+ }
+ /* if we didn't have any sources, just use Inbox as the default */
+ if (sources == 0) {
+ char *defaulturi;
+
+ defaulturi = g_strdup_printf("file://%s/local/Inbox", evolution_dir);
+ d(printf("No sources configured/found, using default: %s\n", defaulturi));
+ sourcefolder = mail_uri_to_folder(defaulturi);
+ g_free(defaulturi);
+ if (sourcefolder)
+ camel_vee_folder_add_folder(folder, sourcefolder);
+ }
+cleanup:
+ g_free(foldername);
+ g_free(storeuri);
+
+ return folder;
+}
+
+static void
+vfolder_editor_clicked(GtkWidget *w, int button, void *data)
+{
+ if (button == 0) {
+ char *user;
+
+ user = g_strdup_printf("%s/vfolders.xml", evolution_dir);
+ rule_context_save((RuleContext *)context, user);
+ g_free(user);
+ vfolder_refresh();
+ }
+ if (button != -1) {
+ gnome_dialog_close((GnomeDialog *)w);
+ }
+}
+
void
vfolder_edit(void)
{
GtkWidget *w;
- char *user;
w = vfolder_editor_construct(context);
- if (gnome_dialog_run_and_close((GnomeDialog *)w) == 0) {
- user = g_strdup_printf ("%s/vfolders.xml", evolution_dir);
- rule_context_save(context, user);
+ gtk_signal_connect((GtkObject *)w, "clicked", vfolder_editor_clicked, NULL);
+ gtk_widget_show(w);
+}
+
+static void
+new_rule_clicked(GtkWidget *w, int button, void *data)
+{
+ if (button == 0) {
+ char *user;
+ FilterRule *rule = gtk_object_get_data((GtkObject *)w, "rule");
+
+ gtk_object_ref((GtkObject *)rule);
+ rule_context_add_rule((RuleContext *)context, rule);
+ user = g_strdup_printf("%s/vfolders.xml", evolution_dir);
+ rule_context_save((RuleContext *)context, user);
g_free(user);
vfolder_refresh();
}
+ if (button != -1) {
+ gnome_dialog_close((GnomeDialog *)w);
+ }
+}
+
+FilterPart *
+vfolder_create_part(const char *name)
+{
+ return rule_context_create_part((RuleContext *)context, name);
+}
+
+/* adds a rule with a gui */
+void
+vfolder_gui_add_rule(VfolderRule *rule)
+{
+ GtkWidget *w;
+ GnomeDialog *gd;
+
+ w = filter_rule_get_widget((FilterRule *)rule, (RuleContext *)context);
+ gd = (GnomeDialog *)gnome_dialog_new("New VFolder", "Ok", "Cancel", NULL);
+ gtk_box_pack_start((GtkBox *)gd->vbox, w, FALSE, TRUE, 0);
+ gtk_widget_show((GtkWidget *)gd);
+ gtk_object_set_data_full((GtkObject *)gd, "rule", rule, (GtkDestroyNotify)gtk_object_unref);
+ gtk_signal_connect((GtkObject *)gd, "clicked", new_rule_clicked, NULL);
+ gtk_widget_show((GtkWidget *)gd);
}