* guile: add mu:timestamp accessor to <mu:message>, implement it
This commit is contained in:
@ -40,6 +40,10 @@ struct _MuMsgWrapper {
|
|||||||
typedef struct _MuMsgWrapper MuMsgWrapper;
|
typedef struct _MuMsgWrapper MuMsgWrapper;
|
||||||
static long MSG_TAG;
|
static long MSG_TAG;
|
||||||
|
|
||||||
|
/* pseudo field, not in Xapian */
|
||||||
|
#define MU_GUILE_MSG_FIELD_ID_TIMESTAMP (MU_MSG_FIELD_ID_NUM + 1)
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
mu_guile_scm_is_msg (SCM scm)
|
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);
|
SCM_ASSERT (scm_integer_p(FIELD), FIELD, SCM_ARG2, FUNC_NAME);
|
||||||
|
|
||||||
mfid = scm_to_int (FIELD);
|
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) {
|
switch (mfid) {
|
||||||
case MU_MSG_FIELD_ID_PRIO: return get_prio_scm (msgwrap->_msg);
|
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;
|
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;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,6 +552,9 @@ static struct {
|
|||||||
{ "mu:field:subject", MU_MSG_FIELD_ID_SUBJECT },
|
{ "mu:field:subject", MU_MSG_FIELD_ID_SUBJECT },
|
||||||
{ "mu:field:tags", MU_MSG_FIELD_ID_TAGS },
|
{ "mu:field:tags", MU_MSG_FIELD_ID_TAGS },
|
||||||
{ "mu:field:to", MU_MSG_FIELD_ID_TO },
|
{ "mu:field:to", MU_MSG_FIELD_ID_TO },
|
||||||
|
|
||||||
|
/* non-Xapian field: timestamp */
|
||||||
|
{ "mu:field:timestamp", MU_GUILE_MSG_FIELD_ID_TIMESTAMP }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -300,7 +300,7 @@ messages if the search expression is omitted).
|
|||||||
@verbatim
|
@verbatim
|
||||||
scheme@(guile-user)> (mu:for-each-message
|
scheme@(guile-user)> (mu:for-each-message
|
||||||
(lambda(msg)
|
(lambda(msg)
|
||||||
(display (subject msg))
|
(display (mu:subject msg))
|
||||||
(newline))
|
(newline))
|
||||||
"subject:coffee")
|
"subject:coffee")
|
||||||
Re: best coffee ever!
|
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: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: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: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
|
@end itemize
|
||||||
|
|
||||||
With these methods, we can query messages for their properties; for example:
|
With these methods, we can query messages for their properties; for example:
|
||||||
|
|||||||
@ -44,6 +44,7 @@
|
|||||||
mu:field:size
|
mu:field:size
|
||||||
mu:field:subject
|
mu:field:subject
|
||||||
mu:field:tags
|
mu:field:tags
|
||||||
|
mu:field:timestamp
|
||||||
mu:field:to))
|
mu:field:to))
|
||||||
|
|
||||||
(load-extension "libguile-mu" "mu_guile_message_init")
|
(load-extension "libguile-mu" "mu_guile_message_init")
|
||||||
@ -74,6 +75,7 @@
|
|||||||
(define-getter mu:size mu:field:size)
|
(define-getter mu:size mu:field:size)
|
||||||
(define-getter mu:subject mu:field:subject)
|
(define-getter mu:subject mu:field:subject)
|
||||||
(define-getter mu:tags mu:field:tags)
|
(define-getter mu:tags mu:field:tags)
|
||||||
|
(define-getter mu:timestamp mu:field:timestamp)
|
||||||
(define-getter mu:to mu:field:to)
|
(define-getter mu:to mu:field:to)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
26
lib/mu-msg.c
26
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*
|
const char*
|
||||||
mu_msg_get_path (MuMsg *self)
|
mu_msg_get_path (MuMsg *self)
|
||||||
{
|
{
|
||||||
@ -535,7 +560,6 @@ mu_msg_contact_new (const char *name, const char *address,
|
|||||||
void
|
void
|
||||||
mu_msg_contact_destroy (MuMsgContact *self)
|
mu_msg_contact_destroy (MuMsgContact *self)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!self)
|
if (!self)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@ -320,7 +320,6 @@ MuMsgPrio mu_msg_get_prio (MuMsg *msg);
|
|||||||
time_t mu_msg_get_timestamp (MuMsg *msg);
|
time_t mu_msg_get_timestamp (MuMsg *msg);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get a specific header from the message. This value will _not_ be
|
* get a specific header from the message. This value will _not_ be
|
||||||
* cached
|
* cached
|
||||||
|
|||||||
Reference in New Issue
Block a user