* 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;
|
||||
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 }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user