mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
b11e5ffd1a
Co-authored-by: Robert Schumann <robert@schumann.link> Co-authored-by: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com>
56 lines
1.5 KiB
Bash
Executable file
56 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
|
|
# delete commented lines before parsing
|
|
done < <(sed '/^[[:space:]]*#/d' "${FETCHMAILRC}")
|
|
|
|
rm "${DEFAULT_FILE}"
|