mirror of https://github.com/djcb/mu.git
* some more work on the guile bindings; somewhat working, still WIP
This commit is contained in:
parent
d91b4ffdf8
commit
c023e2c38c
|
@ -26,23 +26,30 @@ INCLUDES=-I${top_srcdir}/src ${GUILE_CFLAGS} ${GLIB_CFLAGS}
|
|||
AM_CFLAGS=-Wall -Wextra -Wno-unused-parameter -Wdeclaration-after-statement
|
||||
AM_CXXFLAGS=-Wall -Wextra -Wno-unused-parameter
|
||||
|
||||
XFILES= \
|
||||
mu-msg-guile.x
|
||||
|
||||
BUILT_SOURCES=$(XFILES)
|
||||
|
||||
noinst_LTLIBRARIES= \
|
||||
libmuguile.la
|
||||
|
||||
libmuguile_la_SOURCES= \
|
||||
mu-msg-guile.c
|
||||
mu-guile-msg.c \
|
||||
mu-guile-msg.h \
|
||||
mu-guile-store.c \
|
||||
mu-guile-store.h \
|
||||
mu-guile-utils.c \
|
||||
mu-guile-utils.h
|
||||
|
||||
libmuguile_la_LIBADD= \
|
||||
${top_builddir}/src/libmu.la \
|
||||
${GUILE_LIBS}
|
||||
|
||||
XFILES= \
|
||||
mu-guile-msg.x \
|
||||
mu-guile-store.x
|
||||
|
||||
snarfcppopts= $(DEFS) $(AM_CPPFLAGS) $(CPPFLAGS) $(CFLAGS)
|
||||
BUILT_SOURCES=$(XFILES) $(DOCFILES)
|
||||
|
||||
|
||||
snarfcppopts= $(DEFS) $(AM_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) $(INCLUDES)
|
||||
SUFFIXES = .x
|
||||
.c.x:
|
||||
$(GUILE_SNARF) -o $@ $< $(snarfcppopts)
|
||||
|
|
|
@ -17,8 +17,11 @@
|
|||
**
|
||||
*/
|
||||
|
||||
#include <libguile.h>
|
||||
#include <mu-msg.h>
|
||||
#include <mu-query.h>
|
||||
#include <mu-runtime.h>
|
||||
|
||||
#include "mu-guile-msg.h"
|
||||
|
||||
struct _MuMsgWrapper {
|
||||
MuMsg *_msg;
|
||||
|
@ -28,23 +31,35 @@ typedef struct _MuMsgWrapper MuMsgWrapper;
|
|||
|
||||
static long MSG_TAG;
|
||||
|
||||
|
||||
static SCM
|
||||
msg_make_from_file (SCM path)
|
||||
SCM
|
||||
mu_guile_msg_to_scm (MuMsg *msg)
|
||||
{
|
||||
const char* msgpath;
|
||||
MuMsgWrapper *msgwrap;
|
||||
|
||||
msgpath = scm_to_utf8_string (path);
|
||||
|
||||
g_return_val_if_fail (msg, SCM_UNDEFINED);
|
||||
|
||||
msgwrap = scm_gc_malloc (sizeof (MuMsgWrapper), "msg");
|
||||
msgwrap->_msg = mu_msg_new_from_file (msgpath, NULL, NULL);
|
||||
msgwrap->_msg = msg;
|
||||
msgwrap->_unrefme = FALSE;
|
||||
|
||||
SCM_RETURN_NEWSMOB (MSG_TAG, msgwrap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
SCM_DEFINE (msg_make_from_file, "mu:msg:make-from-file", 1, 0, 0,
|
||||
(SCM PATH),
|
||||
"Create a message object based on the message in PATH.\n")
|
||||
#define FUNC_NAME s_msg_make_from_file
|
||||
{
|
||||
MuMsg *msg;
|
||||
|
||||
msg = mu_msg_new_from_file (scm_to_utf8_string (PATH), NULL, NULL);
|
||||
return msg ? SCM_UNDEFINED : mu_guile_msg_to_scm (msg);
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
static SCM
|
||||
msg_str_field (SCM msg_smob, MuMsgFieldId mfid)
|
||||
{
|
||||
|
@ -67,39 +82,50 @@ msg_num_field (SCM msg_smob, MuMsgFieldId mfid)
|
|||
}
|
||||
|
||||
|
||||
static SCM
|
||||
msg_date (SCM msg_smob)
|
||||
SCM_DEFINE (msg_date, "mu:msg:date", 1, 0, 0,
|
||||
(SCM MSG),
|
||||
"Get the date (time in seconds since epoch) for MSG.\n")
|
||||
#define FUNC_NAME s_msg_date
|
||||
{
|
||||
return scm_from_unsigned_integer
|
||||
(msg_num_field (msg_smob, MU_MSG_FIELD_ID_DATE));
|
||||
(msg_num_field (MSG, MU_MSG_FIELD_ID_DATE));
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
static SCM
|
||||
msg_size (SCM msg_smob)
|
||||
|
||||
|
||||
SCM_DEFINE (msg_size, "mu:msg:size", 1, 0, 0,
|
||||
(SCM MSG),
|
||||
"Get the size in bytes for MSG.\n")
|
||||
#define FUNC_NAME s_msg_size
|
||||
{
|
||||
return scm_from_unsigned_integer
|
||||
(msg_num_field (msg_smob, MU_MSG_FIELD_ID_SIZE));
|
||||
(msg_num_field (MSG, MU_MSG_FIELD_ID_SIZE));
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
static SCM
|
||||
msg_prio (SCM msg_smob)
|
||||
|
||||
SCM_DEFINE (msg_prio, "mu:msg:priority", 1, 0, 0,
|
||||
(SCM MSG),
|
||||
"Get the priority of MSG (low, normal or high).\n")
|
||||
#define FUNC_NAME s_msg_prio
|
||||
{
|
||||
MuMsgPrio prio;
|
||||
MuMsgWrapper *msgwrap;
|
||||
msgwrap = (MuMsgWrapper*) SCM_CDR(msg_smob);
|
||||
msgwrap = (MuMsgWrapper*) SCM_CDR(MSG);
|
||||
|
||||
prio = mu_msg_get_prio (msgwrap->_msg);
|
||||
|
||||
switch (prio) {
|
||||
case MU_MSG_PRIO_LOW: return scm_from_utf8_symbol ("low");
|
||||
case MU_MSG_PRIO_NORMAL: return scm_from_utf8_symbol ("normal");
|
||||
case MU_MSG_PRIO_HIGH: return scm_from_utf8_symbol ("high");
|
||||
case MU_MSG_PRIO_LOW: return scm_from_utf8_symbol("low");
|
||||
case MU_MSG_PRIO_NORMAL: return scm_from_utf8_symbol("normal");
|
||||
case MU_MSG_PRIO_HIGH: return scm_from_utf8_symbol("high");
|
||||
default:
|
||||
g_return_val_if_reached (SCM_UNDEFINED);
|
||||
}
|
||||
}
|
||||
|
||||
#undef FUNC_NAME
|
||||
|
||||
struct _FlagData {
|
||||
MuMsgFlags flags;
|
||||
|
@ -118,13 +144,18 @@ check_flag (MuMsgFlags flag, FlagData *fdata)
|
|||
}
|
||||
}
|
||||
|
||||
static SCM
|
||||
msg_flags (SCM msg_smob)
|
||||
|
||||
SCM_DEFINE (msg_flags, "mu:msg:flags", 1, 0, 0,
|
||||
(SCM MSG),
|
||||
"Get the flags for MSG (one or or more of new, passed, replied, "
|
||||
"seen, trashed, draft, flagged, unread, signed, encrypted, "
|
||||
"has-attach).\n")
|
||||
#define FUNC_NAME s_msg_flags
|
||||
{
|
||||
MuMsgWrapper *msgwrap;
|
||||
FlagData fdata;
|
||||
|
||||
msgwrap = (MuMsgWrapper*) SCM_CDR(msg_smob);
|
||||
msgwrap = (MuMsgWrapper*) SCM_CDR(MSG);
|
||||
|
||||
fdata.flags = mu_msg_get_flags (msgwrap->_msg);
|
||||
fdata.lst = SCM_EOL;
|
||||
|
@ -133,20 +164,25 @@ msg_flags (SCM msg_smob)
|
|||
|
||||
return fdata.lst;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
static SCM
|
||||
msg_subject (SCM msg_smob)
|
||||
SCM_DEFINE (msg_subject, "mu:msg:subject", 1, 0, 0,
|
||||
(SCM MSG), "Get the subject of MSG.\n")
|
||||
#define FUNC_NAME s_msg_subject
|
||||
{
|
||||
return msg_str_field (msg_smob, MU_MSG_FIELD_ID_SUBJECT);
|
||||
return msg_str_field (MSG, MU_MSG_FIELD_ID_SUBJECT);
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
static SCM
|
||||
msg_from (SCM msg_smob)
|
||||
|
||||
SCM_DEFINE (msg_from, "mu:msg:from", 1, 0, 0,
|
||||
(SCM MSG), "Get the sender of MSG.\n")
|
||||
#define FUNC_NAME s_msg_from
|
||||
{
|
||||
return msg_str_field (msg_smob, MU_MSG_FIELD_ID_FROM);
|
||||
return msg_str_field (MSG, MU_MSG_FIELD_ID_FROM);
|
||||
}
|
||||
|
||||
#undef FUNC_NAME
|
||||
|
||||
struct _EachContactData {
|
||||
SCM lst;
|
||||
|
@ -160,13 +196,14 @@ contacts_to_list (MuMsgContact *contact, EachContactData *ecdata)
|
|||
if (mu_msg_contact_type (contact) == ecdata->ctype) {
|
||||
SCM item;
|
||||
const char *addr, *name;
|
||||
|
||||
addr = mu_msg_contact_address(contact);
|
||||
name = mu_msg_contact_name(contact);
|
||||
|
||||
item = scm_list_1
|
||||
(scm_list_2 (
|
||||
name ? scm_from_utf8_string(name) : SCM_UNDEFINED,
|
||||
addr ? scm_from_utf8_string(addr) : SCM_UNDEFINED));
|
||||
name ? scm_from_utf8_string(name) : SCM_UNSPECIFIED,
|
||||
addr ? scm_from_utf8_string(addr) : SCM_UNSPECIFIED));
|
||||
|
||||
ecdata->lst = scm_append_x (scm_list_2(ecdata->lst, item));
|
||||
}
|
||||
|
@ -197,57 +234,73 @@ contact_list_field (SCM msg_smob, MuMsgFieldId mfid)
|
|||
}
|
||||
|
||||
|
||||
|
||||
static SCM
|
||||
msg_to (SCM msg_smob)
|
||||
SCM_DEFINE (msg_to, "mu:msg:to", 1, 0, 0,
|
||||
(SCM MSG), "Get the list of To:-recipients of MSG.\n")
|
||||
#define FUNC_NAME s_msg_to
|
||||
{
|
||||
return contact_list_field (msg_smob, MU_MSG_FIELD_ID_TO);
|
||||
return contact_list_field (MSG, MU_MSG_FIELD_ID_TO);
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
|
||||
static SCM
|
||||
msg_cc (SCM msg_smob)
|
||||
SCM_DEFINE (msg_cc, "mu:msg:cc", 1, 0, 0,
|
||||
(SCM MSG), "Get the list of Cc:-recipients of MSG.\n")
|
||||
#define FUNC_NAME s_msg_cc
|
||||
{
|
||||
return contact_list_field (msg_smob, MU_MSG_FIELD_ID_CC);
|
||||
return contact_list_field (MSG, MU_MSG_FIELD_ID_CC);
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
static SCM
|
||||
msg_bcc (SCM msg_smob)
|
||||
SCM_DEFINE (msg_bcc, "mu:msg:bcc", 1, 0, 0,
|
||||
(SCM MSG), "Get the list of Bcc:-recipients of MSG.\n")
|
||||
#define FUNC_NAME s_msg_bcc
|
||||
{
|
||||
return contact_list_field (msg_smob, MU_MSG_FIELD_ID_BCC);
|
||||
return contact_list_field (MSG, MU_MSG_FIELD_ID_BCC);
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
static SCM
|
||||
msg_path (SCM msg_smob)
|
||||
|
||||
SCM_DEFINE (msg_path, "mu:msg:path", 1, 0, 0,
|
||||
(SCM MSG), "Get the filesystem path for MSG.\n")
|
||||
#define FUNC_NAME s_msg_path
|
||||
{
|
||||
return msg_str_field (msg_smob, MU_MSG_FIELD_ID_PATH);
|
||||
return msg_str_field (MSG, MU_MSG_FIELD_ID_PATH);
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
static SCM
|
||||
msg_maildir (SCM msg_smob)
|
||||
SCM_DEFINE (msg_maildir, "mu:msg:maildir", 1, 0, 0,
|
||||
(SCM MSG), "Get the maildir where MSG lives.\n")
|
||||
#define FUNC_NAME s_msg_maildir
|
||||
{
|
||||
return msg_str_field (msg_smob, MU_MSG_FIELD_ID_MAILDIR);
|
||||
return msg_str_field (MSG, MU_MSG_FIELD_ID_MAILDIR);
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
static SCM
|
||||
msg_msgid (SCM msg_smob)
|
||||
|
||||
|
||||
SCM_DEFINE (msg_msgid, "mu:msg:message-id", 1, 0, 0,
|
||||
(SCM MSG), "Get the MSG's message-id.\n")
|
||||
#define FUNC_NAME s_msg_msgid
|
||||
{
|
||||
return msg_str_field (msg_smob, MU_MSG_FIELD_ID_MSGID);
|
||||
return msg_str_field (MSG, MU_MSG_FIELD_ID_MSGID);
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
|
||||
static SCM
|
||||
msg_body (SCM msg_smob, SCM html_smob)
|
||||
SCM_DEFINE (msg_body, "mu:msg:body", 1, 1, 0,
|
||||
(SCM MSG, SCM HTML), "Get the MSG's body. If HTML is #t, "
|
||||
"prefer the html-version, otherwise prefer plain text.\n")
|
||||
#define FUNC_NAME s_msg_body
|
||||
{
|
||||
MuMsgWrapper *msgwrap;
|
||||
gboolean html;
|
||||
const char *val;
|
||||
|
||||
msgwrap = (MuMsgWrapper*) SCM_CDR(msg_smob);
|
||||
html = SCM_UNBNDP(html_smob) ? FALSE : html_smob == SCM_BOOL_T;
|
||||
msgwrap = (MuMsgWrapper*) SCM_CDR(MSG);
|
||||
html = SCM_UNBNDP(HTML) ? FALSE : HTML == SCM_BOOL_T;
|
||||
|
||||
if (html)
|
||||
val = mu_msg_get_body_html(msgwrap->_msg);
|
||||
|
@ -256,21 +309,24 @@ msg_body (SCM msg_smob, SCM html_smob)
|
|||
|
||||
return val ? scm_from_utf8_string (val) : SCM_UNDEFINED;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
static SCM
|
||||
msg_header (SCM msg_smob, SCM header_smob)
|
||||
SCM_DEFINE (msg_header, "mu:msg:header", 1, 1, 0,
|
||||
(SCM MSG, SCM HEADER), "Get an arbitary HEADER from MSG.\n")
|
||||
#define FUNC_NAME s_msg_header
|
||||
{
|
||||
MuMsgWrapper *msgwrap;
|
||||
const char *header;
|
||||
const char *val;
|
||||
|
||||
msgwrap = (MuMsgWrapper*) SCM_CDR(msg_smob);
|
||||
header = scm_to_utf8_string (header_smob);
|
||||
msgwrap = (MuMsgWrapper*) SCM_CDR(MSG);
|
||||
header = scm_to_utf8_string (HEADER);
|
||||
val = mu_msg_get_header(msgwrap->_msg, header);
|
||||
|
||||
return val ? scm_from_utf8_string(val) : SCM_UNDEFINED;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
static SCM
|
||||
msg_string_list_field (SCM msg_smob, MuMsgFieldId mfid)
|
||||
|
@ -292,22 +348,28 @@ msg_string_list_field (SCM msg_smob, MuMsgFieldId mfid)
|
|||
return scmlst;
|
||||
}
|
||||
|
||||
static SCM
|
||||
msg_tags (SCM msg_smob)
|
||||
|
||||
SCM_DEFINE (msg_tags, "mu:msg:tags", 1, 1, 0,
|
||||
(SCM MSG), "Get the list of tags (contents of the "
|
||||
"X-Label:-header) for MSG.\n")
|
||||
#define FUNC_NAME s_msg_tags
|
||||
{
|
||||
return msg_string_list_field (msg_smob, MU_MSG_FIELD_ID_TAGS);
|
||||
return msg_string_list_field (MSG, MU_MSG_FIELD_ID_TAGS);
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
static SCM
|
||||
msg_references (SCM msg_smob)
|
||||
|
||||
SCM_DEFINE (msg_refs, "mu:msg:references", 1, 1, 0,
|
||||
(SCM MSG), "Get the list of referenced message-ids "
|
||||
"(contents of the References: and Reply-To: headers).\n")
|
||||
#define FUNC_NAME s_msg_refs
|
||||
{
|
||||
return msg_string_list_field (msg_smob, MU_MSG_FIELD_ID_REFS);
|
||||
return msg_string_list_field (MSG, MU_MSG_FIELD_ID_REFS);
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static SCM
|
||||
msg_mark (SCM msg_smob)
|
||||
{
|
||||
|
@ -374,9 +436,8 @@ define_symbols (void)
|
|||
}
|
||||
|
||||
|
||||
|
||||
void*
|
||||
mu_msg_guile_register (void *data)
|
||||
mu_guile_msg_init (void *data)
|
||||
{
|
||||
MSG_TAG = scm_make_smob_type ("msg", sizeof(MuMsgWrapper));
|
||||
|
||||
|
@ -386,33 +447,8 @@ mu_msg_guile_register (void *data)
|
|||
|
||||
define_symbols ();
|
||||
|
||||
scm_c_define_gsubr ("make-msg-from-file", 1, 0, 0,
|
||||
&msg_make_from_file);
|
||||
|
||||
scm_c_define_gsubr ("from", 1, 0, 0, &msg_from);
|
||||
#include "mu-guile-msg.x"
|
||||
|
||||
scm_c_define_gsubr ("subject", 1, 0, 0, &msg_subject);
|
||||
scm_c_define_gsubr ("path", 1, 0, 0, &msg_path);
|
||||
scm_c_define_gsubr ("maildir", 1, 0, 0, &msg_maildir);
|
||||
scm_c_define_gsubr ("message-id", 1, 0, 0, &msg_msgid);
|
||||
|
||||
scm_c_define_gsubr ("date", 1, 0, 0, &msg_date);
|
||||
scm_c_define_gsubr ("size", 1, 0, 0, &msg_size);
|
||||
|
||||
scm_c_define_gsubr ("body", 1, 1, 0, &msg_body);
|
||||
scm_c_define_gsubr ("header", 2, 0, 0, &msg_header);
|
||||
|
||||
/* lists */
|
||||
scm_c_define_gsubr ("tags", 1, 0, 0, &msg_tags);
|
||||
scm_c_define_gsubr ("references", 1, 0, 0, &msg_references);
|
||||
scm_c_define_gsubr ("to", 1, 0, 0, &msg_to);
|
||||
scm_c_define_gsubr ("cc", 1, 0, 0, &msg_cc);
|
||||
scm_c_define_gsubr ("bcc", 1, 0, 0, &msg_bcc);
|
||||
|
||||
scm_c_define_gsubr ("priority", 1, 0, 0, &msg_prio);
|
||||
scm_c_define_gsubr ("flags", 1, 0, 0, &msg_flags);
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
** Copyright (C) 2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
** Free Software Foundation; either version 3, or (at your option) any
|
||||
** later version.
|
||||
**
|
||||
** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef __MU_GUILE_MSG_H__
|
||||
#define __MU_GUILE_MSG_H__
|
||||
|
||||
#include <libguile.h>
|
||||
#include <mu-msg.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus*/
|
||||
|
||||
/**
|
||||
* register MuMsg-related functions/smobs with guile; use with
|
||||
* scm_with_guile
|
||||
*
|
||||
*/
|
||||
void *mu_guile_msg_init (void *data);
|
||||
|
||||
|
||||
/**
|
||||
* create an SCM for the MuMsg*
|
||||
*
|
||||
* @param msg a MuMsg instance
|
||||
*
|
||||
* @return an SCM for the msg
|
||||
*/
|
||||
SCM mu_guile_msg_to_scm (MuMsg *msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus*/
|
||||
|
||||
|
||||
#endif /*__MU_GUILE_MSG_H__*/
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
** Copyright (C) 2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
** Free Software Foundation; either version 3, or (at your option) any
|
||||
** later version.
|
||||
**
|
||||
** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
*/
|
||||
|
||||
#include <mu-query.h>
|
||||
#include <mu-store.h>
|
||||
#include <mu-runtime.h>
|
||||
|
||||
#include "mu-guile-msg.h"
|
||||
#include "mu-guile-store.h"
|
||||
#include "mu-guile-utils.h"
|
||||
|
||||
static MuQuery*
|
||||
get_query (void)
|
||||
{
|
||||
MuQuery *query;
|
||||
GError *err;
|
||||
|
||||
err = NULL;
|
||||
query = mu_query_new (mu_runtime_path(MU_RUNTIME_PATH_XAPIANDB), &err);
|
||||
if (err) {
|
||||
g_warning ("error creating query: %s", err->message);
|
||||
g_error_free (err);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
static MuMsgIter*
|
||||
get_query_iter (MuQuery *query, const char* expr)
|
||||
{
|
||||
MuMsgIter *iter;
|
||||
GError *err;
|
||||
|
||||
err = NULL;
|
||||
iter = mu_query_run (query, expr,
|
||||
FALSE, MU_MSG_FIELD_ID_NONE, TRUE, &err);
|
||||
if (err) {
|
||||
g_warning ("error running query: %s", err->message);
|
||||
g_error_free (err);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return iter;
|
||||
}
|
||||
|
||||
|
||||
SCM_DEFINE (store_for_each, "mu:store:foreach", 2, 0, 0,
|
||||
(SCM EXPR, SCM FUNC),
|
||||
"Call FUNC for each message matching EXPR.\n")
|
||||
#define FUNC_NAME s_msg_make_from_file
|
||||
{
|
||||
MuQuery *query;
|
||||
MuMsgIter *iter;
|
||||
//guint count;
|
||||
|
||||
query = get_query ();
|
||||
if (!query)
|
||||
return SCM_UNSPECIFIED;
|
||||
|
||||
iter = get_query_iter (query, scm_to_utf8_string(EXPR));
|
||||
if (!iter)
|
||||
return SCM_UNSPECIFIED;
|
||||
|
||||
while (!mu_msg_iter_is_done(iter)) {
|
||||
|
||||
SCM msgsmob;
|
||||
|
||||
msgsmob = mu_guile_msg_to_scm (mu_msg_iter_get_msg (iter, NULL));
|
||||
|
||||
scm_call_1 (FUNC, msgsmob);
|
||||
|
||||
mu_msg_iter_next (iter);
|
||||
}
|
||||
|
||||
mu_query_destroy (query);
|
||||
|
||||
return SCM_UNSPECIFIED;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
void*
|
||||
mu_guile_store_init (void *data)
|
||||
{
|
||||
#include "mu-guile-store.x"
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** Copyright (C) 2011 <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
|
@ -17,21 +17,23 @@
|
|||
**
|
||||
*/
|
||||
|
||||
#ifndef __MU_MSG_GUILE_H__
|
||||
#define __MU_MSG_GUILE_H__
|
||||
#ifndef __MU_GUILE_STORE_H__
|
||||
#define __MU_GUILE_STORE_H__
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus*/
|
||||
|
||||
/**
|
||||
* register MuMsg-related functions/smobs with guile; use with
|
||||
* scm_with_guile
|
||||
* initialize mu:store functions
|
||||
*
|
||||
* @param data
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
void* mu_msg_guile_register (void *data);
|
||||
*/
|
||||
void *mu_guile_store_init (void *data);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
#endif /*__MU_MSG_GUILE_H__*/
|
||||
#endif /*__cplusplus*/
|
||||
|
||||
#endif /*__MU_GUILE_STORE_H__*/
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
** Copyright (C) 2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
** Free Software Foundation; either version 3, or (at your option) any
|
||||
** later version.
|
||||
**
|
||||
** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
*/
|
||||
|
||||
#include "mu-guile-utils.h"
|
||||
|
||||
void
|
||||
mu_guile_utils_error (const char *func_name, int status,
|
||||
const char *fmt, SCM args)
|
||||
{
|
||||
scm_error_scm (scm_from_locale_symbol ("MuError"),
|
||||
scm_from_utf8_string (func_name ? func_name : "<nameless>"),
|
||||
scm_from_utf8_string (fmt), args,
|
||||
scm_list_1 (scm_from_int (status)));
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
** Copyright (C) 2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
** Free Software Foundation; either version 3, or (at your option) any
|
||||
** later version.
|
||||
**
|
||||
** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**
|
||||
*/
|
||||
|
||||
#ifndef __MU_GUILE_UTILS_H__
|
||||
#define __MU_GUILE_UTILS_H__
|
||||
|
||||
#include <libguile.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /*__cplusplus*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param func_name
|
||||
* @param status
|
||||
* @param fmt
|
||||
* @param args
|
||||
*/
|
||||
void mu_guile_utils_error (const char *func_name, int status,
|
||||
const char *fmt, SCM args);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus*/
|
||||
|
||||
|
||||
#endif /*__MU_GUILE_UTILS_H__*/
|
||||
|
|
@ -78,45 +78,6 @@ typedef enum _MuRuntimePath MuRuntimePath;
|
|||
const char* mu_runtime_path (MuRuntimePath path);
|
||||
|
||||
|
||||
/**
|
||||
* get the mu home directory (typically, ~/.mu); this can only be
|
||||
* called after mu_runtime_init and before mu_runtime_uninit
|
||||
*
|
||||
* @return mu home directory as a string which should be not be
|
||||
* modified, or NULL in case of error.
|
||||
*/
|
||||
const char* mu_runtime_mu_home_dir (void);
|
||||
|
||||
/**
|
||||
* get the xapian directory (typically, ~/.mu/xapian/); this can only
|
||||
* be called after mu_runtime_init and before mu_runtime_uninit
|
||||
*
|
||||
* @return the xapian directory as a string which should be not be
|
||||
* modified, or NULL in case of error.
|
||||
*/
|
||||
const char* mu_runtime_xapian_dir (void);
|
||||
|
||||
|
||||
/**
|
||||
* get the mu bookmarks file (typically, ~/.mu/bookmarks); this can
|
||||
* only be called after mu_runtime_init and before mu_runtime_uninit
|
||||
*
|
||||
* @return the bookmarks file as a string which should be not be
|
||||
* modified, or NULL in case of error.
|
||||
*/
|
||||
const char* mu_runtime_bookmarks_file (void);
|
||||
|
||||
/**
|
||||
* get the mu contacts cache file name (typically,
|
||||
* ~/.mu/contacts.cache); this can only be called after
|
||||
* mu_runtime_init and before mu_runtime_uninit
|
||||
*
|
||||
* @return the contacts cache file name as a string which should be not be
|
||||
* modified, or NULL in case of error.
|
||||
*/
|
||||
const char* mu_runtime_contacts_cache_file (void);
|
||||
|
||||
|
||||
/**
|
||||
* get the mu configuration options (ie., the parsed command line
|
||||
* parameters)
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
include $(top_srcdir)/gtest.mk
|
||||
|
||||
# enforce compiling this dir first before decending into tests/
|
||||
INCLUDES=-I${top_srcdir} ${GUILE_CFLAGS} ${GLIB_CFLAGS}
|
||||
INCLUDES=-I${top_srcdir} -I${top_srcdir}/src ${GUILE_CFLAGS} ${GLIB_CFLAGS}
|
||||
|
||||
# don't use -Werror, as it might break on other compilers
|
||||
# use -Wno-unused-parameters, because some callbacks may not
|
||||
|
|
|
@ -17,15 +17,24 @@
|
|||
**
|
||||
*/
|
||||
|
||||
#include <mu-runtime.h>
|
||||
|
||||
#include <libguile.h>
|
||||
#include <libmuguile/mu-msg-guile.h>
|
||||
#include <libmuguile/mu-guile-msg.h>
|
||||
#include <libmuguile/mu-guile-store.h>
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
scm_with_guile (&mu_msg_guile_register, NULL);
|
||||
|
||||
mu_runtime_init ("/home/djcb/.mu");
|
||||
|
||||
scm_with_guile (&mu_guile_msg_init, NULL);
|
||||
scm_with_guile (&mu_guile_store_init, NULL);
|
||||
|
||||
scm_shell (argc, argv);
|
||||
|
||||
mu_runtime_uninit ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue