#!/bin/sh #---------------------------------------------------------------------------------- # /var/install/bin/archimap-force-archiving - archive mailbox(es) # # Copyright (c) 2002-2025 The Eisfair Team, team(at)eisfair(dot)org # # Creation: 2005-05-16 jed # Last Update: $Id$ # # usage: archimap-force-archiving # archimap-force-archiving --all # archimap-force-archiving -u username # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------------- # read eislib . /var/install/include/eislib #---------------------------------------------------------------------------- # get long name # # input : $1 - username # return: long name #---------------------------------------------------------------------------- get_name () { local _gn_uname="$1" local _gn_ret=1 local _gn_lname=`getent passwd ${_gn_uname} | cut -d: -f5` if [ $? -ne 0 ] then # error - user doesn't exist _gn_lname='' else _gn_ret=0 fi echo "${_gn_lname}" return ${_gn_ret} } #---------------------------------------------------------------------------- # check user # # input : $1 - username # return: 0 - exists # 1 - doesn't exist #---------------------------------------------------------------------------- check_user() { local _cu_user=$1 local _cu_ret=1 if getent passwd ${_cu_user} >/dev/null 2>&1 then _cu_ret=0 else mecho --error "User '${_cu_user}' doesn't exist!" fi return ${_cu_ret} } #---------------------------------------------------------------------------- # create list of users # only active users are listed #---------------------------------------------------------------------------- create_userlist () { local _cu_idx local _cu_active local _cu_user local _cu_name { grep -E "^MAIL_USER_N|^MAIL_USER_[0-9]*_ACTIVE|^MAIL_USER_[0-9]*_USER" ${mailfile} grep -E "^IMAP_PUBLIC_FOLDER_N|^IMAP_PUBLIC_FOLDER_[0-9]*_ACTIVE|^IMAP_SHARED_FOLDER_N|^IMAP_SHARED_FOLDER_[0-9]*_ACTIVE" ${mailfile} } | sed 's/ *# .*$//g' > ${tmpfile} . ${tmpfile} rm -f ${tmpfile} { # imappublic _cu_idx=1 while [ ${_cu_idx} -le ${IMAP_PUBLIC_FOLDER_N} ] do eval _cu_active='$IMAP_PUBLIC_FOLDER_'${_cu_idx}'_ACTIVE' if [ ${_cu_active} = 'yes' ] then _cu_user='imappublic' _cu_name=`get_name "imappublic"` echo "${_cu_user}:${_cu_name}:" break fi _cu_idx=`expr ${_cu_idx} + 1` done # imapshared _cu_idx=1 while [ ${_cu_idx} -le ${IMAP_SHARED_FOLDER_N} ] do eval _cu_active='$IMAP_SHARED_FOLDER_'${_cu_idx}'_ACTIVE' if [ ${_cu_active} = 'yes' ] then _cu_user='imapshared' _cu_name=`get_name "imapshared"` echo "${_cu_user}:${_cu_name}:" break fi _cu_idx=`expr ${_cu_idx} + 1` done # mail users _cu_idx=1 while [ ${_cu_idx} -le ${MAIL_USER_N} ] do eval _cu_active='$MAIL_USER_'${_cu_idx}'_ACTIVE' if [ ${_cu_active} = 'yes' ] then eval _cu_user='$MAIL_USER_'${_cu_idx}'_USER' _cu_name=`get_name "${_cu_user}"` echo "${_cu_user}:${_cu_name}:" fi _cu_idx=`expr ${_cu_idx} + 1` done } | sort | uniq > ${tmpfile} } #---------------------------------------------------------------------------- # print list of users #---------------------------------------------------------------------------- print_userlist () { local _pu_act_pmode local _pu_tty local _pu_row local _pu_user local _pu_name # print header clrhome mecho --info "List users" mecho techo --begin 2 20 40 techo --row "" --info User --info Name _pu_act_pmode=`get_printmode` _pu_tty=`tty` _pu_row=4 while read LINE do _ifs="${IFS}" IFS=: set -- ${LINE} _pu_user="$1" _pu_name="$2" # output data techo --row "" ${_pu_user} ${_pu_name} IFS="${_ifs}" _pu_row=`expr ${_pu_row} + 1` if [ "${_pu_act_pmode}" = 'tty' ] then if [ ${_pu_row} -eq 21 ] then mecho mecho anykey < ${_pu_tty} # print header clrhome mecho --info "List users" < ${_pu_tty} mecho techo --row "" --info User --info Name _pu_row=4 fi fi done < ${tmpfile} techo --end mecho } #---------------------------------------------------------------------------- # print header #---------------------------------------------------------------------------- print_header () { clrhome mecho --info "Force archiving" mecho } #---------------------------------------------------------------------------- # print error message and usage message and exit #---------------------------------------------------------------------------- too_few_args () { mecho --error "Too few arguments" $0 -? exit 1 } #============================================================================ # main #============================================================================ pgmname=`basename $0` mailfile=/etc/config.d/mail archimapfile=/etc/config.d/archimap archimap_configfile=/var/install/config.d/archimap.sh . ${archimapfile} if [ $# -eq 0 ] then pgmname=`basename $0` tmpfile="/tmp/$pgmname-$$" interactive='true' create_userlist print_header uname='' u_exit=0 until [ ${u_exit} -eq 1 ] do if [ -z "${uname}" -o "${uname}" = 'l' ] then # read uname /var/install/bin/ask "Please enter username to force archiving for (user), (a)ll, (l)ist or (q)uit:" '' '+' > /tmp/ask.$$ rc=$? uname=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ $rc = 255 ] then rm ${tmpfile} exit 1 fi fi case ${uname} in a ) # archive all print_header mecho "User: all" mecho /var/install/bin/ask "Force archiving" 'n' > /tmp/ask.$$ rc=$? yesno=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ ${rc} = 255 ] then rm ${tmpfile} exit 1 fi if [ "${yesno}" = 'yes' ] then $0 --all fi u_exit=1 ;; l ) # list users print_userlist ;; q ) # quit u_exit=1 ;; * ) # process user grep -q "^${uname}:" ${tmpfile} if [ $? -eq 0 ] then print_header mecho "User: ${uname}" mecho /var/install/bin/ask "Force archiving" 'n' > /tmp/ask.$$ rc=$? yesno=`cat /tmp/ask.$$` rm -f /tmp/ask.$$ if [ ${rc} = 255 ] then rm ${tmpfile} exit 1 fi if [ "${yesno}" = 'yes' ] then $0 -user ${uname} fi u_exit=1 else uname='' fi ;; esac done rm -f ${tmpfile} else interactive='false' fi case $1 in '--all' ) # force full archiving mecho "force full archiving ..." ${archimap_configfile} --processmboxes ;; -u|-user ) # force single archiving user="$2" [ -z "${user}" ] && too_few_args if check_user ${user} then mecho "force archiving for user '${user}'..." ${archimap_configfile} --processonembox ${user} fi ;; '-?'|'--help' ) # show help mecho "usage: ${pgmname}" >&2 mecho " or: ${pgmname} --all" >&2 mecho " or: ${pgmname} -u login-name" >&2 exit 1 ;; esac if [ "${interactive}" = 'true' ] then mecho anykey fi #============================================================================ # End #============================================================================ exit 0