From b09b9ceaac957112a609b93a7f74084c1669691a Mon Sep 17 00:00:00 2001 From: djcb Date: Tue, 10 Jul 2012 23:36:21 +0300 Subject: [PATCH] * guile: add mu:timestamp accessor to , implement it --- guile/mu-guile-message.c | 16 +++++++++++++++- guile/mu-guile.texi | 7 +++++-- guile/mu/message.scm | 2 ++ lib/mu-msg.c | 26 +++++++++++++++++++++++++- lib/mu-msg.h | 1 - 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/guile/mu-guile-message.c b/guile/mu-guile-message.c index a387d21e..ea9a3ee1 100644 --- a/guile/mu-guile-message.c +++ b/guile/mu-guile-message.c @@ -40,6 +40,10 @@ struct _MuMsgWrapper { typedef struct _MuMsgWrapper MuMsgWrapper; static long MSG_TAG; +/* pseudo field, not in Xapian */ +#define MU_GUILE_MSG_FIELD_ID_TIMESTAMP (MU_MSG_FIELD_ID_NUM + 1) + + static gboolean mu_guile_scm_is_msg (SCM scm) { @@ -250,7 +254,9 @@ SCM_DEFINE_PUBLIC(get_field, "mu:get-field", 2, 0, 0, SCM_ASSERT (scm_integer_p(FIELD), FIELD, SCM_ARG2, FUNC_NAME); mfid = scm_to_int (FIELD); - SCM_ASSERT (mfid < MU_MSG_FIELD_ID_NUM, FIELD, SCM_ARG2, FUNC_NAME); + SCM_ASSERT (mfid < MU_MSG_FIELD_ID_NUM || + mfid == MU_GUILE_MSG_FIELD_ID_TIMESTAMP, + FIELD, SCM_ARG2, FUNC_NAME); switch (mfid) { case MU_MSG_FIELD_ID_PRIO: return get_prio_scm (msgwrap->_msg); @@ -267,6 +273,11 @@ SCM_DEFINE_PUBLIC(get_field, "mu:get-field", 2, 0, 0, return data; } + /* our pseudo-field; we get it from the message file */ + case MU_GUILE_MSG_FIELD_ID_TIMESTAMP: + return scm_from_uint ( + (unsigned)mu_msg_get_timestamp(msgwrap->_msg)); + default: break; } @@ -541,6 +552,9 @@ static struct { { "mu:field:subject", MU_MSG_FIELD_ID_SUBJECT }, { "mu:field:tags", MU_MSG_FIELD_ID_TAGS }, { "mu:field:to", MU_MSG_FIELD_ID_TO }, + + /* non-Xapian field: timestamp */ + { "mu:field:timestamp", MU_GUILE_MSG_FIELD_ID_TIMESTAMP } }; diff --git a/guile/mu-guile.texi b/guile/mu-guile.texi index f97379d3..1a750d75 100644 --- a/guile/mu-guile.texi +++ b/guile/mu-guile.texi @@ -300,7 +300,7 @@ messages if the search expression is omitted). @verbatim scheme@(guile-user)> (mu:for-each-message (lambda(msg) - (display (subject msg)) + (display (mu:subject msg)) (newline)) "subject:coffee") Re: best coffee ever! @@ -346,7 +346,10 @@ refers to in(mu: the @t{References:} header @item @code{(mu:size msg)}: size of the message in bytes @item @code{(mu:subject msg)}: the @t{Subject} field of the message, or @t{#f} if there is none. @item @code{(mu:tags msg)}: list of tags for this message -@item @code{(mu:to msg)}: the sender of the message, or @t{#f} if there is none. +@item @code{(mu:timestamp msg)}: the timestamp (mtime) of the message file, or +#f if there is none. +message file +@item @code{(mu:to msg)}: the sender of the message, or @t{#f} if there is none @end itemize With these methods, we can query messages for their properties; for example: diff --git a/guile/mu/message.scm b/guile/mu/message.scm index bd81bec8..0b6c18f0 100644 --- a/guile/mu/message.scm +++ b/guile/mu/message.scm @@ -44,6 +44,7 @@ mu:field:size mu:field:subject mu:field:tags + mu:field:timestamp mu:field:to)) (load-extension "libguile-mu" "mu_guile_message_init") @@ -74,6 +75,7 @@ (define-getter mu:size mu:field:size) (define-getter mu:subject mu:field:subject) (define-getter mu:tags mu:field:tags) +(define-getter mu:timestamp mu:field:timestamp) (define-getter mu:to mu:field:to) diff --git a/lib/mu-msg.c b/lib/mu-msg.c index 3faae3d3..1330b22a 100644 --- a/lib/mu-msg.c +++ b/lib/mu-msg.c @@ -360,6 +360,31 @@ mu_msg_get_header (MuMsg *self, const char *header) } +time_t +mu_msg_get_timestamp (MuMsg *self) +{ + g_return_val_if_fail (self, 0); + + if (self->_file) + return self->_file->_timestamp; + else { + const char *path; + struct stat statbuf; + + path = mu_msg_get_path (self); + if (!path) + return 0; + + if (stat (path, &statbuf) < 0) + return 0; + + return statbuf.st_mtime; + } +} + + + + const char* mu_msg_get_path (MuMsg *self) { @@ -535,7 +560,6 @@ mu_msg_contact_new (const char *name, const char *address, void mu_msg_contact_destroy (MuMsgContact *self) { - if (!self) return; diff --git a/lib/mu-msg.h b/lib/mu-msg.h index 679a758e..c8f83472 100644 --- a/lib/mu-msg.h +++ b/lib/mu-msg.h @@ -320,7 +320,6 @@ MuMsgPrio mu_msg_get_prio (MuMsg *msg); time_t mu_msg_get_timestamp (MuMsg *msg); - /** * get a specific header from the message. This value will _not_ be * cached