camel-http-stream.c \
camel-index.c \
camel-internet-address.c \
+ camel-junk-plugin.c \
camel-lock.c \
camel-lock-client.c \
camel-medium.c \
camel-index.h \
camel-internet-address.h \
camel-i18n.h \
+ camel-junk-plugin.h \
camel-lock.h \
camel-lock-client.h \
camel-medium.h \
static void digest_rename_folder (CamelStore *store, const char *old, const char *new, CamelException *ex);
static void digest_init_trash (CamelStore *store);
static CamelFolder *digest_get_trash (CamelStore *store, CamelException *ex);
+static void digest_init_junk (CamelStore *store);
+static CamelFolder *digest_get_junk (CamelStore *store, CamelException *ex);
static CamelFolderInfo *digest_get_folder_info (CamelStore *store, const char *top, guint32 flags, CamelException *ex);
store_class->init_trash = digest_init_trash;
store_class->get_trash = digest_get_trash;
+ store_class->init_junk = digest_init_junk;
+ store_class->get_junk = digest_get_junk;
}
static void
{
CamelStore *store = (CamelStore *) obj;
- /* we dont want a vtrash on this one */
- store->flags &= ~(CAMEL_STORE_VTRASH);
+ /* we dont want a vtrash and vjunk on this one */
+ store->flags &= ~(CAMEL_STORE_VTRASH | CAMEL_STORE_VJUNK);
}
static void
return NULL;
}
+static void
+digest_init_junk (CamelStore *store)
+{
+ /* no-op */
+ ;
+}
+
+static CamelFolder *
+digest_get_junk (CamelStore *store, CamelException *ex)
+{
+ return NULL;
+}
+
static CamelFolderInfo *
digest_get_folder_info (CamelStore *store, const char *top, guint32 flags, CamelException *ex)
{
return NULL;
}
-
static ESExpResult *
do_shell (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *driver)
{
static ESExpResult *header_source (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
static ESExpResult *get_size (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
static ESExpResult *pipe_message (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
+static ESExpResult *junk_test (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
/* builtin functions */
static struct {
{ "header-source", (ESExpFunc *) header_source, 0 },
{ "get-size", (ESExpFunc *) get_size, 0 },
{ "pipe-message", (ESExpFunc *) pipe_message, 0 },
+ { "junk-test", (ESExpFunc *) junk_test, 0 },
};
return r;
}
+static ESExpResult *
+junk_test (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms)
+{
+ ESExpResult *r;
+ gboolean retval = FALSE;
+
+ if (fms->session->junk_plugin != NULL) {
+ retval = camel_junk_plugin_check_junk (fms->session->junk_plugin, camel_filter_search_get_message (fms, f));
+
+ fprintf (stderr, "junk filter => %s\n", retval ? "*JUNK*" : "clean");
+ }
+ r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+ r->value.number = retval;
+
+ return r;
+}
+
/**
* camel_filter_search_match:
{ "flagged", CAMEL_MESSAGE_FLAGGED },
{ "seen", CAMEL_MESSAGE_SEEN },
{ "attachments", CAMEL_MESSAGE_ATTACHMENTS },
+ { "junk", CAMEL_MESSAGE_JUNK },
{ NULL, 0 }
};
CAMEL_MESSAGE_SEEN = 1<<4,
CAMEL_MESSAGE_ATTACHMENTS = 1<<5,
CAMEL_MESSAGE_ANSWERED_ALL = 1<<6,
+ CAMEL_MESSAGE_JUNK = 1<<7,
/* following flags are for the folder, and are not really permanent flags */
CAMEL_MESSAGE_FOLDER_FLAGGED = 1<<16, /* for use by the folder implementation */
CamelMessageInfo *info = camel_folder_summary_index(folder->summary, i);
if (info) {
- if (!(info->flags & CAMEL_MESSAGE_SEEN))
+ if (!(info->flags & CAMEL_MESSAGE_SEEN) && (!(info->flags & CAMEL_MESSAGE_JUNK) || (folder->folder_flags & CAMEL_FOLDER_IS_JUNK)))
unread++;
camel_folder_summary_info_free(folder->summary, info);
}
#define CAMEL_FOLDER_FILTER_RECENT (1<<2)
#define CAMEL_FOLDER_HAS_BEEN_DELETED (1<<3)
#define CAMEL_FOLDER_IS_TRASH (1<<4)
+#define CAMEL_FOLDER_IS_JUNK (1<<5)
typedef struct {
CamelObjectClass parent_class;
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Author:
+ * Radek Doulik <rodo@ximian.com>
+ *
+ * Copyright 2003 Ximian, Inc. (www.ximian.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include <stdio.h>
+#include <glib.h>
+#include <camel/camel-junk-plugin.h>
+#include <camel/camel-mime-message.h>
+
+#define d(x) x
+
+const char *
+camel_junk_plugin_get_name (CamelJunkPlugin *csp)
+{
+ g_return_val_if_fail (csp->get_name != NULL, NULL);
+
+ d(fprintf (stderr, "camel_junk_plugin_get_namen");)
+
+ return (*csp->get_name) ();
+}
+
+int
+camel_junk_plugin_check_junk (CamelJunkPlugin *csp, CamelMimeMessage *message)
+{
+ g_return_val_if_fail (csp->check_junk != NULL, FALSE);
+
+ d(fprintf (stderr, "camel_junk_plugin_check_junk\n");)
+
+ return (*csp->check_junk) (message);
+}
+
+void
+camel_junk_plugin_report_junk (CamelJunkPlugin *csp, CamelMimeMessage *message)
+{
+ d(fprintf (stderr, "camel_junk_plugin_report_junk\n");)
+
+ if (csp->report_junk)
+ (*csp->report_junk) (message);
+}
+
+void
+camel_junk_plugin_report_notjunk (CamelJunkPlugin *csp, CamelMimeMessage *message)
+{
+ d(fprintf (stderr, "camel_junk_plugin_report_notjunk\n");)
+
+ if (csp->report_notjunk)
+ (*csp->report_notjunk) (message);
+}
+
+void
+camel_junk_plugin_commit_reports (CamelJunkPlugin *csp)
+{
+ d(fprintf (stderr, "camel_junk_plugin_commit_reports\n");)
+
+ if (csp->commit_reports)
+ (*csp->commit_reports) ();
+}
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Author:
+ * Radek Doulik <rodo@ximian.com>
+ *
+ * Copyright 2003 Ximian, Inc. (www.ximian.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifndef _CAMEL_JUNK_PLUGIN_H
+#define _CAMEL_JUNK_PLUGIN_H
+
+#define CAMEL_JUNK_PLUGIN(x) ((CamelJunkPlugin *) x)
+
+typedef struct _CamelJunkPlugin CamelJunkPlugin;
+struct _CamelMimeMessage;
+
+struct _CamelJunkPlugin
+{
+ /* junk filter human readable name, translated */
+ const char * (*get_name) (void);
+
+ /* should be set to 1 */
+ int api_version;
+
+ /* when called, it should return TRUE if message is identified as junk,
+ FALSE otherwise */
+ int (*check_junk) (struct _CamelMimeMessage *message);
+
+ /* called when user identified a message to be junk */
+ void (*report_junk) (struct _CamelMimeMessage *message);
+
+ /* called when user identified a message not to be junk */
+ void (*report_notjunk) (struct _CamelMimeMessage *message);
+
+ /* called after one or more junk/ham(s) reported */
+ void (*commit_reports) (void);
+};
+
+const char * camel_junk_plugin_get_name (CamelJunkPlugin *csp);
+int camel_junk_plugin_check_junk (CamelJunkPlugin *csp, struct _CamelMimeMessage *message);
+void camel_junk_plugin_report_junk (CamelJunkPlugin *csp, struct _CamelMimeMessage *message);
+void camel_junk_plugin_report_notjunk (CamelJunkPlugin *csp, struct _CamelMimeMessage *message);
+void camel_junk_plugin_commit_reports (CamelJunkPlugin *csp);
+
+#endif
#include <camel/camel-object.h>
#include <camel/camel-provider.h>
+#include <camel/camel-junk-plugin.h>
#include <e-util/e-msgport.h>
char *storage_path;
GHashTable *providers, *modules;
gboolean online;
+
+ CamelJunkPlugin *junk_plugin;
};
#ifdef ENABLE_THREADS
static void init_trash (CamelStore *store);
static CamelFolder *get_trash (CamelStore *store, CamelException *ex);
+static void init_junk (CamelStore *store);
+static CamelFolder *get_junk (CamelStore *store, CamelException *ex);
+
static CamelFolderInfo *create_folder (CamelStore *store,
const char *parent_name,
const char *folder_name,
camel_store_class->get_inbox = get_inbox;
camel_store_class->init_trash = init_trash;
camel_store_class->get_trash = get_trash;
+ camel_store_class->init_junk = init_junk;
+ camel_store_class->get_junk = get_junk;
camel_store_class->create_folder = create_folder;
camel_store_class->delete_folder = delete_folder;
camel_store_class->rename_folder = rename_folder;
} else
store->folders = NULL;
- /* set vtrash on by default */
- store->flags = CAMEL_STORE_VTRASH;
+ /* set vtrash and vjunk on by default */
+ store->flags = CAMEL_STORE_VTRASH | CAMEL_STORE_VJUNK;
store->dir_sep = '/';
if (!folder) {
folder = CS_CLASS (store)->get_folder (store, folder_name, flags, ex);
if (folder) {
- /* Add the folder to the vTrash folder if this store implements it */
+ /* Add the folder to the vTrash/vJunk folder if this store implements it */
if (store->vtrash)
camel_vee_folder_add_folder (CAMEL_VEE_FOLDER (store->vtrash), folder);
+ if (store->vjunk)
+ camel_vee_folder_add_folder (CAMEL_VEE_FOLDER (store->vjunk), folder);
if (store->folders)
camel_object_bag_add(store->folders, folder_name, folder);
/* NB: Note similarity of this code to unsubscribe_folder */
- /* if we deleted a folder, force it out of the cache, and also out of the vtrash if setup */
+ /* if we deleted a folder, force it out of the cache, and also out of the vtrash/vjunk if setup */
if (store->folders) {
folder = camel_object_bag_get(store->folders, folder_name);
if (folder) {
if (store->vtrash)
camel_vee_folder_remove_folder((CamelVeeFolder *)store->vtrash, folder);
+ if (store->vjunk)
+ camel_vee_folder_remove_folder((CamelVeeFolder *)store->vjunk, folder);
camel_folder_delete (folder);
}
}
}
static void
-init_trash (CamelStore *store)
+junk_finalize (CamelObject *junk, gpointer event_data, gpointer user_data)
{
- if ((store->flags & CAMEL_STORE_VTRASH) == 0)
- return;
+ CamelStore *store = CAMEL_STORE (user_data);
+
+ store->vjunk = NULL;
+}
- store->vtrash = camel_vtrash_folder_new (store, CAMEL_VTRASH_NAME);
+/* FIXME: derive vjunk folder object from vee_folder */
+#include "camel-vee-store.h"
+static CamelFolder *
+camel_vjunk_folder_new (CamelStore *parent_store, const char *name)
+{
+ CamelFolder *vjunk;
- if (store->vtrash) {
+ vjunk = (CamelFolder *)camel_object_new (camel_vee_folder_get_type ());
+ vjunk->folder_flags |= CAMEL_FOLDER_IS_JUNK;
+ camel_vee_folder_construct (CAMEL_VEE_FOLDER (vjunk), parent_store, name,
+ CAMEL_STORE_FOLDER_PRIVATE | CAMEL_STORE_FOLDER_CREATE | CAMEL_STORE_VEE_FOLDER_AUTO);
+ camel_vee_folder_set_expression((CamelVeeFolder *)vjunk, "(match-all (system-flag \"Junk\"))");
+
+ return vjunk;
+}
+
+static void
+init_trash_or_junk (CamelStore *store, CamelFolder *folder, void (*finalize) (CamelObject *o, gpointer event_data, gpointer user_data))
+{
+ if (folder) {
/* FIXME: this should probably use the object bag or another one ? ... */
- /* attach to the finalise event of the vtrash */
- camel_object_hook_event (store->vtrash, "finalize",
- trash_finalize, store);
+ /* attach to the finalise event of the vtrash/vjunk */
+ camel_object_hook_event (folder, "finalize", finalize, store);
- /* add all the pre-opened folders to the vtrash */
+ /* add all the pre-opened folders to the vtrash/vjunk */
if (store->folders) {
GPtrArray *folders = camel_object_bag_list(store->folders);
int i;
for (i=0;i<folders->len;i++) {
- camel_vee_folder_add_folder (CAMEL_VEE_FOLDER (store->vtrash), (CamelFolder *)folders->pdata[i]);
+ camel_vee_folder_add_folder (CAMEL_VEE_FOLDER (folder), (CamelFolder *)folders->pdata[i]);
camel_object_unref(folders->pdata[i]);
}
g_ptr_array_free(folders, TRUE);
}
}
+static void
+init_trash (CamelStore *store)
+{
+ if ((store->flags & CAMEL_STORE_VTRASH) == 0)
+ return;
+
+ store->vtrash = camel_vtrash_folder_new (store, CAMEL_VTRASH_NAME);
+ init_trash_or_junk (store, store->vtrash, trash_finalize);
+}
+
+static void
+init_junk (CamelStore *store)
+{
+ if ((store->flags & CAMEL_STORE_VJUNK) == 0)
+ return;
+
+ store->vjunk = camel_vjunk_folder_new (store, CAMEL_VJUNK_NAME);
+ init_trash_or_junk (store, store->vjunk, junk_finalize);
+}
static CamelFolder *
get_trash (CamelStore *store, CamelException *ex)
}
}
+static CamelFolder *
+get_junk (CamelStore *store, CamelException *ex)
+{
+ if (store->vjunk) {
+ camel_object_ref (CAMEL_OBJECT (store->vjunk));
+ return store->vjunk;
+ } else {
+ CS_CLASS (store)->init_junk (store);
+ if (store->vjunk) {
+ /* We don't ref here because we don't want the
+ store to own a ref on the junk folder */
+ /*camel_object_ref (CAMEL_OBJECT (store->vjunk));*/
+ return store->vjunk;
+ } else {
+ w(g_warning ("This store does not support vJunk."));
+ return NULL;
+ }
+ }
+}
+
/**
* camel_store_get_trash:
* @store: a CamelStore
return folder;
}
+/**
+ * camel_store_get_junk:
+ * @store: a CamelStore
+ * @ex: a CamelException
+ *
+ * Return value: the folder in the store into which junk is
+ * delivered, or %NULL if no such folder exists.
+ **/
+CamelFolder *
+camel_store_get_junk (CamelStore *store, CamelException *ex)
+{
+ CamelFolder *folder;
+
+ if ((store->flags & CAMEL_STORE_VJUNK) == 0)
+ return NULL;
+
+ CAMEL_STORE_LOCK(store, folder_lock);
+ folder = CS_CLASS (store)->get_junk (store, ex);
+ CAMEL_STORE_UNLOCK(store, folder_lock);
+
+ return folder;
+}
+
static void
store_sync (CamelStore *store, CamelException *ex)
{
/* NB: Note similarity of this code to delete_folder */
- /* if we deleted a folder, force it out of the cache, and also out of the vtrash if setup */
+ /* if we deleted a folder, force it out of the cache, and also out of the vtrash/vjunk if setup */
if (store->folders) {
folder = camel_object_bag_get(store->folders, folder_name);
if (folder) {
if (store->vtrash)
camel_vee_folder_remove_folder((CamelVeeFolder *)store->vtrash, folder);
+ if (store->vjunk)
+ camel_vee_folder_remove_folder((CamelVeeFolder *)store->vjunk, folder);
camel_folder_delete (folder);
}
}
#define CAMEL_STORE_SUBSCRIPTIONS (1 << 0)
#define CAMEL_STORE_VTRASH (1 << 1)
#define CAMEL_STORE_FILTER_INBOX (1 << 2)
+#define CAMEL_STORE_VJUNK (1 << 3)
struct _CamelStore
{
struct _CamelStorePrivate *priv;
CamelFolder *vtrash;
+ CamelFolder *vjunk;
CamelObjectBag *folders;
void (*init_trash) (CamelStore *store);
CamelFolder * (*get_trash) (CamelStore *store,
CamelException *ex);
+ void (*init_junk) (CamelStore *store);
+ CamelFolder * (*get_junk) (CamelStore *store,
+ CamelException *ex);
CamelFolderInfo *(*create_folder) (CamelStore *store,
const char *parent_name,
CamelException *ex);
CamelFolder * camel_store_get_trash (CamelStore *store,
CamelException *ex);
+CamelFolder * camel_store_get_junk (CamelStore *store,
+ CamelException *ex);
CamelFolderInfo *camel_store_create_folder (CamelStore *store,
const char *parent_name,
static void vee_rename_folder(CamelStore *store, const char *old, const char *new, CamelException *ex);
static void vee_init_trash (CamelStore *store);
static CamelFolder *vee_get_trash (CamelStore *store, CamelException *ex);
+static void vee_init_junk (CamelStore *store);
+static CamelFolder *vee_get_junk (CamelStore *store, CamelException *ex);
static CamelFolderInfo *vee_get_folder_info(CamelStore *store, const char *top, guint32 flags, CamelException *ex);
store_class->init_trash = vee_init_trash;
store_class->get_trash = vee_get_trash;
+ store_class->init_junk = vee_init_junk;
+ store_class->get_junk = vee_get_junk;
}
static void
{
CamelStore *store = (CamelStore *)obj;
- /* we dont want a vtrash on this one */
- store->flags &= ~(CAMEL_STORE_VTRASH);
+ /* we dont want a vtrash/vjunk on this one */
+ store->flags &= ~(CAMEL_STORE_VTRASH | CAMEL_STORE_VJUNK);
}
static void
return NULL;
}
+static void
+vee_init_junk (CamelStore *store)
+{
+ /* no-op */
+ ;
+}
+
+static CamelFolder *
+vee_get_junk (CamelStore *store, CamelException *ex)
+{
+ return NULL;
+}
+
static CamelFolderInfo *
vee_get_folder_info(CamelStore *store, const char *top, guint32 flags, CamelException *ex)
{
if (store->vtrash)
camel_vee_folder_remove_folder((CamelVeeFolder *)store->vtrash, folder);
+ if (store->vjunk)
+ camel_vee_folder_remove_folder((CamelVeeFolder *)store->vjunk, folder);
if ((((CamelVeeFolder *)folder)->flags & CAMEL_STORE_FOLDER_PRIVATE) == 0) {
/* what about now-empty parents? ignore? */
#include <camel/camel-vee-folder.h>
#define CAMEL_VTRASH_NAME "Trash"
+#define CAMEL_VJUNK_NAME "Junk"
#define CAMEL_VTRASH_FOLDER(obj) CAMEL_CHECK_CAST (obj, camel_vtrash_folder_get_type (), CamelVTrashFolder)
#define CAMEL_VTRASH_FOLDER_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_vtrash_folder_get_type (), CamelVTrashFolderClass)