[evolution-data-server] Bug #269413 - Search treats "4 weeks" and "1 month" as synonymous
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Bug #269413 - Search treats "4 weeks" and "1 month" as synonymous
- Date: Mon, 20 Jun 2011 11:57:26 +0000 (UTC)
commit b6ab0d14906400350a9a2bf50b3d8292a7fc9c1d
Author: Milan Crha <mcrha redhat com>
Date: Mon Jun 20 13:56:46 2011 +0200
Bug #269413 - Search treats "4 weeks" and "1 month" as synonymous
camel/camel-filter-search.c | 20 ++++++++++++++++
camel/camel-folder-search.c | 50 +++++++++++++++++++++++++++++++++++++++++
camel/camel-folder-search.h | 5 ++++
camel/camel-search-sql-sexp.c | 21 +++++++++++++++++
4 files changed, 96 insertions(+), 0 deletions(-)
---
diff --git a/camel/camel-filter-search.c b/camel/camel-filter-search.c
index 1c6a521..cf8ef83 100644
--- a/camel/camel-filter-search.c
+++ b/camel/camel-filter-search.c
@@ -88,6 +88,7 @@ static ESExpResult *system_flag (struct _ESExp *f, gint argc, struct _ESExpResul
static ESExpResult *get_sent_date (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
static ESExpResult *get_received_date (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
static ESExpResult *get_current_date (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
+static ESExpResult *get_relative_months (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
static ESExpResult *header_source (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
static ESExpResult *get_size (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
static ESExpResult *pipe_message (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms);
@@ -117,6 +118,7 @@ static struct {
{ "get-sent-date", (ESExpFunc *) get_sent_date, 0 },
{ "get-received-date", (ESExpFunc *) get_received_date, 0 },
{ "get-current-date", (ESExpFunc *) get_current_date, 0 },
+ { "get-relative-months",(ESExpFunc *) get_relative_months,0 },
{ "header-source", (ESExpFunc *) header_source, 0 },
{ "get-size", (ESExpFunc *) get_size, 0 },
{ "pipe-message", (ESExpFunc *) pipe_message, 0 },
@@ -460,6 +462,24 @@ get_current_date (struct _ESExp *f, gint argc, struct _ESExpResult **argv, Filte
return r;
}
+static ESExpResult *
+get_relative_months (struct _ESExp *f, gint argc, struct _ESExpResult **argv, FilterMessageSearch *fms)
+{
+ ESExpResult *r;
+
+ if (argc != 1 || argv[0]->type != ESEXP_RES_INT) {
+ r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+ r->value.boolean = FALSE;
+
+ g_debug ("%s: Expecting 1 argument, an integer, but got %d arguments", G_STRFUNC, argc);
+ } else {
+ r = e_sexp_result_new (f, ESEXP_RES_INT);
+ r->value.number = camel_folder_search_util_add_months (time (NULL), argv[0]->value.number);
+ }
+
+ return r;
+}
+
static CamelService *
get_service_for_source (CamelSession *session, const gchar *src)
{
diff --git a/camel/camel-folder-search.c b/camel/camel-folder-search.c
index af8cf3b..78597c0 100644
--- a/camel/camel-folder-search.c
+++ b/camel/camel-folder-search.c
@@ -84,6 +84,7 @@ static ESExpResult *search_system_flag (struct _ESExp *f, gint argc, struct _ESE
static ESExpResult *search_get_sent_date (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
static ESExpResult *search_get_received_date (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
static ESExpResult *search_get_current_date (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+static ESExpResult *search_get_relative_months (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
static ESExpResult *search_get_size (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
static ESExpResult *search_uid (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
static ESExpResult *search_message_location (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
@@ -149,6 +150,7 @@ camel_folder_search_class_init (CamelFolderSearchClass *class)
class->get_sent_date = search_get_sent_date;
class->get_received_date = search_get_received_date;
class->get_current_date = search_get_current_date;
+ class->get_relative_months = search_get_relative_months;
class->get_size = search_get_size;
class->uid = search_uid;
class->message_location = search_message_location;
@@ -196,6 +198,7 @@ static struct {
{ "get-sent-date", G_STRUCT_OFFSET(CamelFolderSearchClass, get_sent_date), 1 },
{ "get-received-date", G_STRUCT_OFFSET(CamelFolderSearchClass, get_received_date), 1 },
{ "get-current-date", G_STRUCT_OFFSET(CamelFolderSearchClass, get_current_date), 1 },
+ { "get-relative-months", G_STRUCT_OFFSET(CamelFolderSearchClass, get_relative_months), 1 },
{ "get-size", G_STRUCT_OFFSET(CamelFolderSearchClass, get_size), 1 },
{ "uid", G_STRUCT_OFFSET(CamelFolderSearchClass, uid), 1 },
{ "message-location", G_STRUCT_OFFSET(CamelFolderSearchClass, message_location), 1 },
@@ -1761,6 +1764,26 @@ search_get_current_date (struct _ESExp *f, gint argc, struct _ESExpResult **argv
}
static ESExpResult *
+search_get_relative_months (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s)
+{
+ ESExpResult *r;
+
+ r(printf("executing get-relative-months\n"));
+
+ if (argc != 1 || argv[0]->type != ESEXP_RES_INT) {
+ r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+ r->value.boolean = FALSE;
+
+ g_debug ("%s: Expecting 1 argument, an integer, but got %d arguments", G_STRFUNC, argc);
+ } else {
+ r = e_sexp_result_new (f, ESEXP_RES_INT);
+ r->value.number = camel_folder_search_util_add_months (time (NULL), argv[0]->value.number);
+ }
+
+ return r;
+}
+
+static ESExpResult *
search_get_size (struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s)
{
ESExpResult *r;
@@ -1872,3 +1895,30 @@ search_message_location (struct _ESExp *f, gint argc, struct _ESExpResult **argv
return r;
}
+
+/* add or subtract given number of months to given time */
+time_t
+camel_folder_search_util_add_months (time_t t, gint months)
+{
+ GDateTime *dt, *dt2;
+ time_t res;
+
+ if (!months)
+ return t;
+
+ dt = g_date_time_new_from_unix_utc (t);
+
+ /* just for issues, to return something inaccurate, but sane */
+ res = t + (60 * 60 * 24 * 30 * months);
+
+ g_return_val_if_fail (dt != NULL, res);
+
+ dt2 = g_date_time_add_months (dt, months);
+ g_date_time_unref (dt);
+ g_return_val_if_fail (dt2 != NULL, res);
+
+ res = g_date_time_to_unix (dt2);
+ g_date_time_unref (dt2);
+
+ return res;
+}
diff --git a/camel/camel-folder-search.h b/camel/camel-folder-search.h
index e8ba03e..cdd65e5 100644
--- a/camel/camel-folder-search.h
+++ b/camel/camel-folder-search.h
@@ -137,6 +137,9 @@ struct _CamelFolderSearchClass {
/* (get-current-date) Retrieve 'now' as a time_t */
ESExpResult * (*get_current_date)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+ /* (get-relative-months) Retrieve relative seconds from 'now' and specified number of months as a time_t */
+ ESExpResult * (*get_relative_months)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
+
/* (get-size) Retrieve message size as an gint (in kilobytes) */
ESExpResult * (*get_size)(struct _ESExp *f, gint argc, struct _ESExpResult **argv, CamelFolderSearch *s);
@@ -163,6 +166,8 @@ GPtrArray *camel_folder_search_search (CamelFolderSearch *search, const gchar *e
guint32 camel_folder_search_count (CamelFolderSearch *search, const gchar *expr, GError **error);
void camel_folder_search_free_result (CamelFolderSearch *search, GPtrArray *);
+time_t camel_folder_search_util_add_months (time_t t, gint months);
+
G_END_DECLS
#endif /* CAMEL_FOLDER_SEARCH_H */
diff --git a/camel/camel-search-sql-sexp.c b/camel/camel-search-sql-sexp.c
index 53bbf11..25ee6a8 100644
--- a/camel/camel-search-sql-sexp.c
+++ b/camel/camel-search-sql-sexp.c
@@ -536,6 +536,26 @@ get_current_date (struct _ESExp *f, gint argc, struct _ESExpResult **argv, gpoin
}
static ESExpResult *
+get_relative_months (struct _ESExp *f, gint argc, struct _ESExpResult **argv, gpointer data)
+{
+ ESExpResult *r;
+
+ d(printf("executing get-relative-months\n"));
+
+ if (argc != 1 || argv[0]->type != ESEXP_RES_INT) {
+ r = e_sexp_result_new (f, ESEXP_RES_BOOL);
+ r->value.boolean = FALSE;
+
+ g_debug ("%s: Expecting 1 argument, an integer, but got %d arguments", G_STRFUNC, argc);
+ } else {
+ r = e_sexp_result_new (f, ESEXP_RES_INT);
+ r->value.number = camel_folder_search_util_add_months (time (NULL), argv[0]->value.number);
+ }
+
+ return r;
+}
+
+static ESExpResult *
get_size (struct _ESExp *f, gint argc, struct _ESExpResult **argv, gpointer data)
{
ESExpResult *r;
@@ -595,6 +615,7 @@ static struct {
{ "get-sent-date", get_sent_date, 0},
{ "get-received-date", get_received_date, 0},
{ "get-current-date", get_current_date, 0},
+ { "get-relative-months", get_relative_months, 0},
{ "get-size", get_size, 0},
{ "sql-exp", sql_exp, 0},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]