Skip to content

Instantly share code, notes, and snippets.

@scripting
Created September 3, 2019 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scripting/43fc83d0cbfe811dcac284fa3890f291 to your computer and use it in GitHub Desktop.
Save scripting/43fc83d0cbfe811dcac284fa3890f291 to your computer and use it in GitHub Desktop.
This is a typical XML-RPC server written in JavaScript as of today. There's still more cleanup to do, for example, you shouldn't have to specify flPostEnabled in config, since XML-RPC calls are only made via POST, it can be handled at the lower level.
const xmlrpc = require ("davexmlrpc");
const utils = require ("daveutils");
const davehttp = require ("davehttp");
const mail = require ("davemail");
const fs = require ("fs");
var config = {
port: 1417,
flPostEnabled: true,
flLogToConsole: true,
xmlRpcPath: "/rpc2"
}
xmlrpc.startServerOverHttp (config, function (xmlRpcRequest) {
function mailSend (params, callback) {
var recipient = params [0];
var title = params [1];
var mailtext = params [2];
var sender = params [3];
mail.send (recipient, title, mailtext, sender, function (err, data) {
callback (err, data);
});
}
switch (xmlRpcRequest.verb) {
case "mail.send":
mailSend (xmlRpcRequest.params, xmlRpcRequest.returnVal);
return (true); //we handled it
}
return (false); //we didn't handle it
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment