mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
061fe12aa7
* Migrate PR#1730 from tomav/docker-mailserver repo to new docker-mailserver/docker-mailserver repo * Resolved review comments * Moved counter increment to have consistency between fetchmail process and fetchmail config files * Added tests for new fetchmail option Co-authored-by: Georg Lauterbach <44545919+aendeavor@users.noreply.github.com>
55 lines
1.5 KiB
Bash
Executable file
55 lines
1.5 KiB
Bash
Executable file
#! /bin/bash
|
|
|
|
# Description: This script will split the content of /etc/fetchmailrc into
|
|
# smaller fetchmailrc files per server [poll] entries. Each
|
|
# separate fetchmailrc file is stored in /etc/fetchmailrc.d
|
|
#
|
|
# The mail purpose for this is to work around what is known
|
|
# as the Fetchmail IMAP idle issue.
|
|
#
|
|
|
|
FETCHMAILRC="/etc/fetchmailrc"
|
|
FETCHMAILRCD="/etc/fetchmailrc.d"
|
|
DEFAULT_FILE="${FETCHMAILRCD}/defaults"
|
|
|
|
if [[ ! -r "${FETCHMAILRC}" ]]
|
|
then
|
|
echo "Error: File ${FETCHMAILRC} not found"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -d ${FETCHMAILRCD} ]]
|
|
then
|
|
if ! mkdir "${FETCHMAILRCD}"
|
|
then
|
|
echo "Error: Unable to create folder ${FETCHMAILRCD}"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
COUNTER=0
|
|
SERVER=0
|
|
while read -r LINE
|
|
do
|
|
if [[ ${LINE} =~ poll ]]
|
|
then
|
|
# If we read "poll" then we reached a new server definition
|
|
# We need to create a new file with fetchmail defaults from
|
|
# /etc/fetcmailrc
|
|
COUNTER=$((COUNTER+1))
|
|
SERVER=1
|
|
cat "${DEFAULT_FILE}" > "${FETCHMAILRCD}/fetchmail-${COUNTER}.rc"
|
|
echo "${LINE}" >> "${FETCHMAILRCD}/fetchmail-${COUNTER}.rc"
|
|
elif [[ ${SERVER} -eq 0 ]]
|
|
then
|
|
# We have not yet found "poll". Let's assume we are still reading
|
|
# the default settings from /etc/fetchmailrc file
|
|
echo "${LINE}" >> "${DEFAULT_FILE}"
|
|
else
|
|
# Just the server settings that need to be added to the specific rc.d file
|
|
echo "${LINE}" >> "${FETCHMAILRCD}/fetchmail-${COUNTER}.rc"
|
|
fi
|
|
done < "${FETCHMAILRC}"
|
|
|
|
rm "${DEFAULT_FILE}"
|