mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-23 15:37:01 +00:00
aliases: Implement aliases hooks
This patch implements two new hooks: alias-resolve and alias-exists. They are called during the aliases resolution process, to allow for more complex integration with other systems, such as storing the aliases in a database. See the included documentation for more details.
This commit is contained in:
15
test/t-04-aliases/alias-exists-hook
Executable file
15
test/t-04-aliases/alias-exists-hook
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
case "$1" in
|
||||
"vicuña@testserver")
|
||||
exit 0
|
||||
;;
|
||||
"ñandú@testserver")
|
||||
exit 0
|
||||
;;
|
||||
"roto@testserver")
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 1
|
||||
14
test/t-04-aliases/alias-resolve-hook
Executable file
14
test/t-04-aliases/alias-resolve-hook
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
case "$1" in
|
||||
"vicuña@testserver")
|
||||
# Test one naked, one full. These exist in the static aliases file.
|
||||
echo pepe, joan@testserver
|
||||
;;
|
||||
"ñandú@testserver")
|
||||
echo "| writemailto ../.data/pipe_alias_worked"
|
||||
;;
|
||||
"roto@testserver")
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -22,6 +22,10 @@ function send_and_check() {
|
||||
done
|
||||
}
|
||||
|
||||
# Remove the hooks that could be left over from previous failed tests.
|
||||
rm -f config/hooks/alias-resolve
|
||||
rm -f config/hooks/alias-exists
|
||||
|
||||
# Test email aliases.
|
||||
send_and_check pepe jose
|
||||
send_and_check joan juan
|
||||
@@ -39,5 +43,32 @@ run_msmtp tubo@testserver < content
|
||||
wait_for_file .data/pipe_alias_worked
|
||||
mail_diff content .data/pipe_alias_worked
|
||||
|
||||
# Set up the hooks.
|
||||
mkdir -p config/hooks/
|
||||
cp alias-exists-hook config/hooks/alias-exists
|
||||
cp alias-resolve-hook config/hooks/alias-resolve
|
||||
|
||||
# Test email aliases.
|
||||
send_and_check vicuña juan jose
|
||||
|
||||
# Test the pipe alias separately.
|
||||
rm -f .data/pipe_alias_worked
|
||||
run_msmtp ñandú@testserver < content
|
||||
wait_for_file .data/pipe_alias_worked
|
||||
mail_diff content .data/pipe_alias_worked
|
||||
|
||||
# Test when alias-resolve exits with an error
|
||||
if run_msmtp roto@testserver < content 2> .logs/msmtp.out; then
|
||||
echo "expected delivery to roto@ to fail, but succeeded"
|
||||
fi
|
||||
|
||||
# Test a non-existent alias.
|
||||
if run_msmtp nono@testserver < content 2> .logs/msmtp.out; then
|
||||
echo "expected delivery to nono@ to fail, but succeeded"
|
||||
fi
|
||||
|
||||
# Remove the hooks, leave a clean state.
|
||||
rm -f config/hooks/alias-resolve
|
||||
rm -f config/hooks/alias-exists
|
||||
|
||||
success
|
||||
|
||||
Reference in New Issue
Block a user