diff options
author | Jonas Smedegaard <dr@jones.dk> | 2002-12-24 19:39:23 +0000 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2002-12-24 19:39:23 +0000 |
commit | f0f6dc7c4887d21debbaaf817e5db70137c59fac (patch) | |
tree | 27c43ad049978eff7d03dbc6708f3cdc4f3528f4 /userforward | |
parent | 03142063b852bb038951db3f24ef47a9006a3d93 (diff) |
Forward incoming mailspool if found.
Rename username variable 'uid' to the more correct 'user'.
Check and fail if uid of user is below 1000.
Standardize error messages.
Diffstat (limited to 'userforward')
-rwxr-xr-x | userforward | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/userforward b/userforward index 4aa4c21..88f2413 100755 --- a/userforward +++ b/userforward @@ -5,16 +5,22 @@ if [ $# \< 2 -o $# \> 3 ]; then exit 1 fi -uid=$1 +user=$1 addr=$2 force=$3 set -e -homedir=`getent passwd $uid | awk -F: '{print $6}';` +uid=`id -u $user` +if [ $uid \< 1000 ]; then + echo "ERROR: User is not a real user (uid too low)!" + exit 1 +fi + +homedir=`getent passwd $user | awk -F: '{print $6}';` if [ -e $homedir/.forward -a "x$force" != "xforce" ]; then - echo "User \"$uid\" already has a .forward - (add \"force\" to overwrite...)" + echo "ERROR: User \"$user\" already has a .forward (add \"force\" to overwrite...)!" exit 1 fi @@ -22,9 +28,21 @@ if [ -d $homedir ]; then touch $homedir/.forward echo "echo $addr>$homedir/.forward" echo $addr>$homedir/.forward - chown $uid. $homedir/.forward - echo "Done!" + chown $user. $homedir/.forward else - echo "Problem with user \"$uid\": Homedir \"$homedir\" doesn't exist - exiting..." + echo "ERROR: Homedir \"$homedir\" of user \"$user\" doesn't exist!" exit 1 fi + +mailspool=/var/mail/$user +thismaildomain=`cat /etc/mailname 2> /dev/null || hostname -d` + +if [ -f $mailspool ]; then + if [ -s $mailspool -a -x /usr/bin/formail -a -x /usr/lib/sendmail ]; then + /usr/bin/formail -A "X-Resent-By: postmaster@$thismaildomain" -i "To: $addr" -R Cc: Old-Cc: -R Bcc: Old-Bcc: -s /usr/lib/sendmail -t < $mailspool + rm -f $mailspool + echo "Old incoming mails forwarded to new account." + else + echo "OBS! Old incoming mails not forwarded." +fi +echo "Done!" |