From bc9c77215d8ded150c18a73e7af7a6a7ead90177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Sun, 24 Oct 2021 12:05:30 +0200 Subject: [PATCH] add targetmail and bash completion for trashmail --- bash_completion.d/trashmail | 14 ++++++++++++++ bin/trashmail | 9 +++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 bash_completion.d/trashmail diff --git a/bash_completion.d/trashmail b/bash_completion.d/trashmail new file mode 100644 index 0000000..5636f26 --- /dev/null +++ b/bash_completion.d/trashmail @@ -0,0 +1,14 @@ +#!/bin/bash + +function _trashmail() { + COMPREPLY=() + local CUR KEYS + CUR="${COMP_WORDS[COMP_CWORD]}" + KEYS=$(ldapsearch -LLL -Z -H ldap://${LDAP_HOST_DEFAULT} -D ${LDAP_ADMIN_BIND_DN} -x -w $(pass ${PASS_ID_LDAP_ADMIN}|head -n 1) -b ou=mailaccounts,dc=schuerz,dc=at '(&(dcAccountStatus=active)(objectClass=dcExternalMailAccount))' dcSubMailAddress|grep "^dcSubMailAddress"|awk '{print $2}') + COMPREPLY=( $(compgen -W "${KEYS}" -- ${CUR}) ) + return 0 +} +complete -F _trashmail trashmail + + + diff --git a/bin/trashmail b/bin/trashmail index 10a1d5b..c9d03dd 100755 --- a/bin/trashmail +++ b/bin/trashmail @@ -34,6 +34,7 @@ show_help () { --help show this help/usage -l|--length |full cut hashed part of username to characters from start (default: ${HASHLENGHT_DEFAULT}) -n|--not-hashed do not hash username from targetdomain and linux-login-user + -t|--target-mail Emailadress for which trashmail is created -w|--full-hash do not cut hash (same as »-l full«) -y|--symbols same option as in pwgen. Include at least one special character in the password. @@ -43,8 +44,8 @@ EOF } # TODO: how exit main-shell from error in subshell??? -getopt -u -o dfhl:nwy --long delete,force,hashed,help,not-hashed,hashlength:,whole-hash,symblols -- "$@" || exit $? -set -- $(getopt -u -o dfhl:nwy --long delete,force,hashed,help,not-hashed,hashlength:,whole-hash,symblols -- "$@"|| exit $?) +getopt -u -o dfhl:nt:wy --long delete,force,hashed,help,not-hashed,hashlength:,whole-hash,symblols,target-mail: -- "$@" || exit $? +set -- $(getopt -u -o dfhl:nt:wy --long delete,force,hashed,help,not-hashed,hashlength:,whole-hash,symblols,target-mail: -- "$@"|| exit $?) echo @: $@ while : ; do @@ -77,6 +78,10 @@ while : ; do HASHED=false shift ;; + -t|--target-mail) + TARGET_MAIL=$2 + shift; shift; + ;; -w|--full-hash) HASHLENGTH=full shift;