mirror of https://github.com/djcb/mu.git
parent
3aa053e158
commit
6a7e706354
|
@ -17,6 +17,7 @@
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
#include "mu-guile-message.hh"
|
#include "mu-guile-message.hh"
|
||||||
|
#include "libguile/scm.h"
|
||||||
#include "mu-message-flags.hh"
|
#include "mu-message-flags.hh"
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
@ -196,8 +197,7 @@ SCM_DEFINE(get_field,
|
||||||
|
|
||||||
switch (mu_msg_field_type(mfid)) {
|
switch (mu_msg_field_type(mfid)) {
|
||||||
case MU_MSG_FIELD_TYPE_STRING:
|
case MU_MSG_FIELD_TYPE_STRING:
|
||||||
return mu_guile_scm_from_str(mu_msg_get_field_string(msgwrap->_msg, mfid));
|
return mu_guile_scm_from_str(mu_msg_get_field_string(msgwrap->_msg, mfid)); case MU_MSG_FIELD_TYPE_BYTESIZE:
|
||||||
case MU_MSG_FIELD_TYPE_BYTESIZE:
|
|
||||||
case MU_MSG_FIELD_TYPE_TIME_T:
|
case MU_MSG_FIELD_TYPE_TIME_T:
|
||||||
return scm_from_uint(mu_msg_get_field_numeric(msgwrap->_msg, mfid));
|
return scm_from_uint(mu_msg_get_field_numeric(msgwrap->_msg, mfid));
|
||||||
case MU_MSG_FIELD_TYPE_INT:
|
case MU_MSG_FIELD_TYPE_INT:
|
||||||
|
@ -208,25 +208,20 @@ SCM_DEFINE(get_field,
|
||||||
}
|
}
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
|
|
||||||
struct _EachContactData {
|
static SCM
|
||||||
SCM lst;
|
contacts_to_list(MuMsg *msg, Mu::MessageContact::Type mtype)
|
||||||
MuMsgContactType ctype;
|
|
||||||
};
|
|
||||||
typedef struct _EachContactData EachContactData;
|
|
||||||
|
|
||||||
static void
|
|
||||||
contacts_to_list(MuMsgContact* contact, EachContactData* ecdata)
|
|
||||||
{
|
{
|
||||||
SCM item;
|
SCM list{SCM_EOL};
|
||||||
|
|
||||||
if (ecdata->ctype != MU_MSG_CONTACT_TYPE_ALL &&
|
const auto contacts{mu_msg_get_contacts(msg, mtype)};
|
||||||
mu_msg_contact_type(contact) != ecdata->ctype)
|
for (auto&& contact: mu_msg_get_contacts(msg, mtype)) {
|
||||||
return;
|
SCM item{scm_list_1(
|
||||||
|
scm_cons(mu_guile_scm_from_str(contact.name.c_str()),
|
||||||
|
mu_guile_scm_from_str(contact.email.c_str())))};
|
||||||
|
list = scm_append_x(scm_list_2(list, item));
|
||||||
|
}
|
||||||
|
|
||||||
item = scm_list_1(scm_cons(mu_guile_scm_from_str(mu_msg_contact_name(contact)),
|
return list;
|
||||||
mu_guile_scm_from_str(mu_msg_contact_email(contact))));
|
|
||||||
|
|
||||||
ecdata->lst = scm_append_x(scm_list_2(ecdata->lst, item));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM_DEFINE(get_contacts,
|
SCM_DEFINE(get_contacts,
|
||||||
|
@ -239,7 +234,8 @@ SCM_DEFINE(get_contacts,
|
||||||
#define FUNC_NAME s_get_contacts
|
#define FUNC_NAME s_get_contacts
|
||||||
{
|
{
|
||||||
MuMsgWrapper* msgwrap;
|
MuMsgWrapper* msgwrap;
|
||||||
EachContactData ecdata;
|
SCM list;
|
||||||
|
Mu::MessageContact::Type mtype;
|
||||||
|
|
||||||
MU_GUILE_INITIALIZED_OR_ERROR;
|
MU_GUILE_INITIALIZED_OR_ERROR;
|
||||||
|
|
||||||
|
@ -251,34 +247,35 @@ SCM_DEFINE(get_contacts,
|
||||||
|
|
||||||
if (CONTACT_TYPE == SCM_BOOL_F)
|
if (CONTACT_TYPE == SCM_BOOL_F)
|
||||||
return SCM_UNSPECIFIED; /* nothing to do */
|
return SCM_UNSPECIFIED; /* nothing to do */
|
||||||
else if (CONTACT_TYPE == SCM_BOOL_T)
|
|
||||||
ecdata.ctype = MU_MSG_CONTACT_TYPE_ALL;
|
if (CONTACT_TYPE == SCM_BOOL_T)
|
||||||
|
mtype = Mu::MessageContact::Type::Unknown; /* get all */
|
||||||
else {
|
else {
|
||||||
if (scm_is_eq(CONTACT_TYPE, SYMB_CONTACT_TO))
|
if (scm_is_eq(CONTACT_TYPE, SYMB_CONTACT_TO))
|
||||||
ecdata.ctype = MU_MSG_CONTACT_TYPE_TO;
|
mtype = Mu::MessageContact::Type::To;
|
||||||
else if (scm_is_eq(CONTACT_TYPE, SYMB_CONTACT_CC))
|
else if (scm_is_eq(CONTACT_TYPE, SYMB_CONTACT_CC))
|
||||||
ecdata.ctype = MU_MSG_CONTACT_TYPE_CC;
|
mtype = Mu::MessageContact::Type::Cc;
|
||||||
else if (scm_is_eq(CONTACT_TYPE, SYMB_CONTACT_BCC))
|
else if (scm_is_eq(CONTACT_TYPE, SYMB_CONTACT_BCC))
|
||||||
ecdata.ctype = MU_MSG_CONTACT_TYPE_BCC;
|
mtype = Mu::MessageContact::Type::Bcc;
|
||||||
else if (scm_is_eq(CONTACT_TYPE, SYMB_CONTACT_FROM))
|
else if (scm_is_eq(CONTACT_TYPE, SYMB_CONTACT_FROM))
|
||||||
ecdata.ctype = MU_MSG_CONTACT_TYPE_FROM;
|
mtype = Mu::MessageContact::Type::From;
|
||||||
else {
|
else {
|
||||||
mu_guile_error(FUNC_NAME, 0, "invalid contact type", SCM_UNDEFINED);
|
mu_guile_error(FUNC_NAME, 0, "invalid contact type", SCM_UNDEFINED);
|
||||||
return SCM_UNSPECIFIED;
|
return SCM_UNSPECIFIED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ecdata.lst = SCM_EOL;
|
|
||||||
msgwrap = (MuMsgWrapper*)SCM_CDR(MSG);
|
msgwrap = (MuMsgWrapper*)SCM_CDR(MSG);
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wcast-function-type"
|
#pragma GCC diagnostic ignored "-Wcast-function-type"
|
||||||
mu_msg_contact_foreach(msgwrap->_msg, (MuMsgContactForeachFunc)contacts_to_list, &ecdata);
|
list = contacts_to_list(msgwrap->_msg, mtype);
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
/* explicitly close the file backend, so we won't run out of fds */
|
/* explicitly close the file backend, so we won't run out of fds */
|
||||||
mu_msg_unload_msg_file(msgwrap->_msg);
|
mu_msg_unload_msg_file(msgwrap->_msg);
|
||||||
|
|
||||||
return ecdata.lst;
|
return list;
|
||||||
}
|
}
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue