1:- module(bc_api_mail, []).

HTTP handlers for mail system */

    5:- use_module(library(arouter)).    6:- use_module(library(dict_schema)).    7
    8:- use_module(bc_api_io).    9:- use_module(bc_api_auth).   10:- use_module(bc_api_actor).   11:- use_module(bc_mail).   12
   13% Tests the mail system with the posted
   14% parameters.
   15
   16:- route_post(api/mail/test,
   17    bc_auth, mail_test).   18
   19mail_test:-
   20    bc_actor(Actor),
   21    bc_read_by_schema(bc_mail_test, Params),
   22    bc_mail_test(Actor, Params, Result),
   23    (   Result = ok
   24    ->  bc_reply_success(true)
   25    ;   (   Result = error(E)
   26        ->  message_to_string(E, String),
   27            bc_reply_error(String)
   28        ;   (   Result = fail
   29            ->  bc_reply_error('Sending failed')
   30            ;   bc_reply_error('Unknown result')))).
   31
   32% Generic config entry.
   33
   34:- register_schema(bc_mail_test, _{
   35    type: dict,
   36    keys: _{
   37        host: atom,
   38        user: atom,
   39        password: atom,
   40        auth: atom,
   41        security: atom,
   42        from: atom,
   43        subject: atom,
   44        body: atom
   45    },
   46    additional: true
   47}).