//
// SPDX-FileCopyrightText: 2026 Graeme Walker <graeme_walker@users.sourceforge.net>
// SPDX-License-Identifier: FSFAP
//
// Copyright (c) 2026 Graeme Walker <graeme_walker@users.sourceforge.net>
//
// Copying and distribution of this file, with or without modification,
// are permitted in any medium without royalty provided the copyright
// notice and this notice are preserved. This file is offered as-is,
// without any warranty.
// ===
//
// emailrelay-list-verify.js
//
// An example E-MailRelay address verifier script for
// Windows that uses a hard-coded list of recipient
// addresses.
//
try
{
var to = WScript.Arguments(0) ;
//var from = WScript.Arguments(1) ;
//var ip = WScript.Arguments(2) ;
var domain = WScript.Arguments(3) ;
//var mechanism = WScript.Arguments(4) ;
//var id = WScript.Arguments(5) ;
// list of recognised recipient addresses
//
var users = [
["alice",""] , // valid
["bob",""] , // valid
["carol","carol.smith@"+domain] , // valid, with mapping
["dave","@david"] , // local mailbox, with mapping
["erol","@"] , // local mailbox
["malory","@@"] // abort
] ;
// split the recipient address and check the domain part
var re = new RegExp( "([^@]*)@(.*)" ) ;
var user_part = to.match(re)[1] ;
var domain_part = to.match(re)[2] ;
if( domain_part.toLowerCase() !== domain )
{
WScript.StdOut.WriteLine( "invalid address" ) ;
WScript.StdOut.WriteLine( "invalid domain-part ["+domain_part+"]" ) ;
WScript.Quit( 2 ) ;
}
// case-insensitive match of the user part
var user_key = "" ;
var user_value = "" ;
for( var i = 0 ; i < users.length ; i++ )
{
var user = users[i] ;
if( user_part.toLowerCase() === user[0].toLowerCase() )
{
user_key = user[0] ;
user_value = user[1] ;
break ;
}
}
if( user_value.charAt(0) === '@' && user_value !== "@@" )
{
// valid local recipient address with a mailbox
var mailbox = user_value === "@" ? user_key : user_value.substr(1) ;
WScript.StdOut.WriteLine( to ) ;
WScript.StdOut.WriteLine( mailbox ) ;
WScript.Quit( 0 ) ;
}
else if( user_key.length && user_value !== "@@" )
{
// valid recipient address
var address = user_value.length ? user_value : (user_part+"@"+domain) ;
WScript.StdOut.WriteLine( "" ) ;
WScript.StdOut.WriteLine( address ) ;
WScript.Quit( 1 ) ;
}
else if( user_value === "@@" )
{
// abort
WScript.Quit( 100 ) ;
}
else
{
WScript.StdOut.WriteLine( "invalid address" ) ;
WScript.StdOut.WriteLine( "invalid user-part ["+user_part+"]" ) ;
WScript.Quit( 2 ) ;
}
}
catch( e )
{
WScript.StdOut.WriteLine( "error" ) ;
WScript.StdOut.WriteLine( e.name + ": " + e.message ) ;
WScript.Quit( 3 ) ; // temporary failure
}