#!/bin/bash # # Expects USER and HOME to be set as an environment variable # Note: with PostfixAdmin, HOME incudes a trailing slash SCRIPT_NAME="quota-warning" MAIL_TO="${USER}" POSITION=`expr index "$MAIL_TO" @` DOMAIN=${MAIL_TO:POSITION} MAIL_FROM="postmaster@${DOMAIN}" MAIL_QUOTA_PERCENT=$1 MAIL_SUBJECT="IMPORTANT: Your Mailbox is "$1"% full!" DIR_MAILDIR_NEW="${HOME}new" DIR_MAILDIR_TMP="${HOME}tmp" BIN_CAT="/bin/cat" BIN_DATE="/bin/date" BIN_HOSTNAME="/bin/hostname" BIN_LOGGER="/usr/bin/logger" BIN_MV="/bin/mv" BIN_STAT="/usr/bin/stat" #set -x # check for user [ "x${MAIL_TO}" = "x" ] && \ ${BIN_LOGGER} -p mail.error -t "${SCRIPT_NAME}" \ "error=no user set" && exit 1 # check for home directory [ "x${HOME}" = "x" ] && \ ${BIN_LOGGER} -p mail.error -t "${SCRIPT_NAME}(${MAIL_TO})" \ "no home directory set" && exit 1 # check for directories [ ! -d "${DIR_MAILDIR_NEW}" ] && \ ${BIN_LOGGER} -p mail.error -t "${SCRIPT_NAME}(${MAIL_TO})" \ "cannot find ${DIR_MAILDIR_NEW}" && exit 1 [ ! -d "${DIR_MAILDIR_TMP}" ] && \ ${BIN_LOGGER} -p mail.error -t "${SCRIPT_NAME}(${MAIL_TO})" \ "cannot find ${DIR_MAILDIR_TMP}" && exit 1 # set misc values HOSTNAME="`${BIN_HOSTNAME}`" # set mail value MAIL_DATE="`${BIN_DATE} '+%a, %d %b %Y %T %z (%Z)'`" MAIL_MESSAGE_ID="`${BIN_DATE} '+%Y%m%d%H%M%S'`@${HOSTNAME}" # set filename values FILE_DATE="`${BIN_DATE} '+%s'`" FILE_NAME="${FILE_DATE}.$$.${HOSTNAME}" FILE_TMP="${DIR_MAILDIR_TMP}/${FILE_NAME}" # write out message ${BIN_CAT} << EOF > ${FILE_TMP} To: ${MAIL_TO} From: ${MAIL_FROM} Subject: ${MAIL_SUBJECT} Message-Id: <${MAIL_MESSAGE_ID}> Date: ${MAIL_DATE} MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit Hello ============ It appears that your mailbox on the server host.domain.tld is greater than ${MAIL_QUOTA_PERCENT}% of its capacity. Once the mailbox is nearly full, delivery of some messages addressed to you may be delayed until you make room for them. There is a possibility you will loose mail. The sender should receive a message that their message was not delivered, but there is no guarantee they will get this notification, and of course, there is no guarantee they care to resend messages if needed. Some messages sent to you may be sent by automated systems that have no way to receive these delayed or returned mail notifications, or to resend messages. Once your mailbox is full, your Sent folder will no longer store the messages you send. You may still be able to send mail, but you will have no record of the sent message. So what can I do? ===================== The simple answer is to delete messages you no longer need, then empty (Purge) your Trash. If using the SquirrelMail web based email client: https://host.domain.tld/mail then your only real choice is to do just that. Note that initially as you delete messages, some messages you delete may not go to your Trash folder at all, but are deleted immediately. As you delete messages, click on (Check Mail) and then Purge your trash. Consider also deleting items from the Sent folder. The SquirrelMail web based email client shows how much of your quota has been used, so even if you don't normally use this software, it is helpful to use it to determine how much of your quota remains. Other mail clients may allow you to move items from your mailbox, to files located on your computer. For example, Outlook Express may have a "Local Folders" folder where messages can be moved. Assuming Outlook Express is configured as an IMAP client, don't forget to use the Purge function after deleting or moving messages. If using Outlook, you may have an Archive folder, or Personal Folders that you can move messages in to. If not, then it is simple to create one. Something like: File->New->Outlook Data File->OK->OK. Other email clients may have similar functionality. ===================================================================== If using a POP3 client, and you access your mailbox from several computers, you may have set the "Keep Mail on Server" option in your email client. Normally, this option would not be set and a POP3 client would download messages to your computer and remove them from the server. The disadvantage of not keeping mail on the server would be the inability to access the mail from more than one POP3 client. However, at least one of the clients you use must not use the option to "Keep Mail on Server" so messages are eventually removed. ========================================== What if I need help? ========================================== If you have questions, you can send a message to ${MAIL_FROM} or call support at (555) 555-1212 Thank You EOF [ "$?" -gt 0 ] && \ ${BIN_LOGGER} -p mail.error -t "${SCRIPT_NAME}(${MAIL_TO})" \ "writing message to ${FILE_TMP} failed" && exit 1 # set more filename values FILE_SIZE="`${BIN_STAT} --printf='%s' ${FILE_TMP}`" FILE_NEW="${DIR_MAILDIR_NEW}/${FILE_NAME},S=${FILE_SIZE}" # deliver message ${BIN_MV} ${FILE_TMP} ${FILE_NEW} [ "$?" -gt 0 ] && \ ${BIN_LOGGER} -p mail.error -t "${SCRIPT_NAME}(${MAIL_TO})" \ "delivering message to ${FILE_NEW} failed" && exit 1 # log warning attempt ${BIN_LOGGER} -p mail.info -t "${SCRIPT_NAME}(${MAIL_TO}) ${MAIL_QUOTA_PERCENT}%" "delivered"