|
WFTK_EXPORT void repos_notify_direct (XML * repository, const char * list_key, const char * key, XML * obj, XML * notification,
const char * subject, const char * recipient)
{
char * text_view;
char * html_view;
XML * list = repos_defn (repository, list_key);
XML * obj_in = obj;
char * subject_in;
char * from_in;
char * recipient_in;
WFTK_ADAPTOR * ad;
if (*xml_attrval (notification, "lookup")) repos_notify (repository, list_key, key, obj, xml_attrval (notification, "lookup"), subject, recipient);
if (!obj_in) obj_in = repos_get (repository, list_key, key);
repos_log (repository, 6, 2, NULL, "notification", "repos_notify: notification going out (%s) (%s)", recipient, subject);
/* 1. Get text and HTML views required by notification. */
text_view = xmlobj_get (notification, NULL, "text");
html_view = xmlobj_get (notification, NULL, "html");
if (!text_view && !html_view) {
if (xml_first (notification) && !xml_firstelem (notification)) {
text_view = xml_stringcontent (notification);
}
}
if (!text_view && !html_view) {
xml_set (notification, "textmode", *xml_attrval (notification, "viewmode") ? xml_attrval (notification, "viewmode") : "notification");
xml_set (notification, "htmlmode", *xml_attrval (notification, "viewmode") ? xml_attrval (notification, "viewmode") : "notification");
xml_attrcat (notification, "textmode", "_text");
xml_attrcat (notification, "textmode", "_html");
text_view = repos_view_find (repository, list, obj_in, xml_attrval (notification, "textmode"));
html_view = repos_view_find (repository, list, obj_in, xml_attrval (notification, "htmlmode"));
}
if (!text_view && !html_view) {
text_view = xml_strdup ("\n");
}
/* Express said views. */
if (text_view) text_view = repos_view_express (repository, list, obj_in, text_view);
if (html_view) html_view = repos_view_express (repository, list, obj_in, html_view);
/* Prepare extra info (subject and recipient) */
/*repos_log (repository, 6, 2, NULL, "notification", "repos_notify: notification structure:\n%s\n", xml_string (notification));*/
xml_set_nodup (notification, "subject", xmlobj_get (notification, NULL, "subject"));
xml_set_nodup (notification, "to", xmlobj_get (notification, NULL, "to"));
xml_set_nodup (notification, "from", xmlobj_get (notification, NULL, "from"));
if (subject) subject_in = xmlobj_format (obj_in, list, subject);
else subject_in = xmlobj_format (obj_in, list, xml_attrval (notification, "subject"));
if (recipient) recipient_in = xmlobj_format (obj_in, list, recipient);
else recipient_in = xmlobj_format (obj_in, list, xml_attrval (notification, "to"));
from_in = xmlobj_format (obj_in, list, xml_attrval (notification, "from"));
/* Get the appropriate adaptor and send the message. */
/* TODO: message logging, in-repository rich messaging. */
ad = wftk_get_adaptor (repository, NOTIFY, xml_attrval (notification, "type")); /* TODO: all that cool preference logic from wftk-bare. */
if (ad) {
wftk_call_adaptor (ad, "send", recipient_in, from_in, subject_in, text_view, html_view);
if (*xml_attrval (ad->parms, "error")) {
repos_log (repository, 2, 2, NULL, "notification", "repos_notify: error sending: %s", xml_attrval (ad->parms, "error"));
xml_set (notification, "error", xml_attrval (ad->parms, "error"));
}
wftk_free_adaptor (repository, ad);
} else {
repos_log (repository, 1, 2, NULL, "notification", "repos_notify: attempted notification with unknown adaptor");
}
/* TODO: ability to send mail with attachments -- for this, need to think out attachment specification formalism. */
/* Clean up. */
free (text_view);
if (html_view) free (html_view);
free (from_in);
free (recipient_in);
free (subject_in);
if (!obj) xml_free (obj_in);
}
|