From d9ca3676e409eb87156bfe1be3f34666830b077d Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Mon, 18 May 2020 23:53:20 +0200 Subject: [PATCH] Add fetchmail and pingmail to mail setup. --- buster/apt-mark/mail | 2 + .../mail/etc/systemd/system/fetchmail.service | 8 ++++ .../mail/etc/systemd/system/pingmail.service | 7 +++ .../timers.target.wants/fetchmail.timer | 8 ++++ .../system/timers.target.wants/pingmail.timer | 8 ++++ buster/other_files/fetchmailrc | 2 + buster/other_files/pingmailrc | 45 +++++++++++++++++++ buster/setup_scripts/setup_mail.sh | 21 +++++++-- 8 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 buster/etc_files/mail/etc/systemd/system/fetchmail.service create mode 100644 buster/etc_files/mail/etc/systemd/system/pingmail.service create mode 100644 buster/etc_files/mail/etc/systemd/system/timers.target.wants/fetchmail.timer create mode 100644 buster/etc_files/mail/etc/systemd/system/timers.target.wants/pingmail.timer create mode 100755 buster/other_files/fetchmailrc create mode 100644 buster/other_files/pingmailrc diff --git a/buster/apt-mark/mail b/buster/apt-mark/mail index 0956960..1ef369d 100644 --- a/buster/apt-mark/mail +++ b/buster/apt-mark/mail @@ -13,3 +13,5 @@ dovecot-imapd # sieve filtering dovecot-lmtpd dovecot-sieve +# to funnel mail from additional server +fetchmail diff --git a/buster/etc_files/mail/etc/systemd/system/fetchmail.service b/buster/etc_files/mail/etc/systemd/system/fetchmail.service new file mode 100644 index 0000000..dc8acb4 --- /dev/null +++ b/buster/etc_files/mail/etc/systemd/system/fetchmail.service @@ -0,0 +1,8 @@ +[Unit] +Description=Run plom's fetchmail + +[Service] +Type=oneshot +User=plom +# fetchmail returns 1 when no new mail, we want to catch that +ExecStart=/bin/sh -c 'fetchmail || [ $? -eq 1 ]' diff --git a/buster/etc_files/mail/etc/systemd/system/pingmail.service b/buster/etc_files/mail/etc/systemd/system/pingmail.service new file mode 100644 index 0000000..e332114 --- /dev/null +++ b/buster/etc_files/mail/etc/systemd/system/pingmail.service @@ -0,0 +1,7 @@ +[Unit] +Description=Run pingmail check + +[Service] +Type=oneshot +User=plom +ExecStart=/bin/sh -c '~/pingmail/pingmail check' diff --git a/buster/etc_files/mail/etc/systemd/system/timers.target.wants/fetchmail.timer b/buster/etc_files/mail/etc/systemd/system/timers.target.wants/fetchmail.timer new file mode 100644 index 0000000..c67e8e7 --- /dev/null +++ b/buster/etc_files/mail/etc/systemd/system/timers.target.wants/fetchmail.timer @@ -0,0 +1,8 @@ +[Unit] +Description=Run fetchmail once every minute + +[Timer] +OnCalendar=*-*-* *:*:00 + +[Install] +WantedBy=timers.target diff --git a/buster/etc_files/mail/etc/systemd/system/timers.target.wants/pingmail.timer b/buster/etc_files/mail/etc/systemd/system/timers.target.wants/pingmail.timer new file mode 100644 index 0000000..dba0c9f --- /dev/null +++ b/buster/etc_files/mail/etc/systemd/system/timers.target.wants/pingmail.timer @@ -0,0 +1,8 @@ +[Unit] +Description=Run pingmail check once every hour + +[Timer] +OnCalendar=*-*-* *:00:00 + +[Install] +WantedBy=timers.target diff --git a/buster/other_files/fetchmailrc b/buster/other_files/fetchmailrc new file mode 100755 index 0000000..b437563 --- /dev/null +++ b/buster/other_files/fetchmailrc @@ -0,0 +1,2 @@ +# remove "keep" if you're sure about your setup; it keeps mails on server from getting deleted +poll mail.example.com protocol pop3 username "foo@example.com" password "PASSWORD" ssl keep diff --git a/buster/other_files/pingmailrc b/buster/other_files/pingmailrc new file mode 100644 index 0000000..46bcbfe --- /dev/null +++ b/buster/other_files/pingmailrc @@ -0,0 +1,45 @@ +# place for test files whose modification times are used to track lifesigns +testdir=$HOME'/.pingmail' + +# modification time is the last time a ping was sent or a lifetime received +ping_touch=$testdir'/ping_touch' + +# modification time is when the count for sending checker a warning mail starts +reminder_touch=$testdir'/reminder_touch' + +# how long to wait for lifesigns before sending a ping; double is time to wait +# for a lifesign before sending a warning message to checker +wait_time=86400 + +# address of the checker, receives warning message after too long wait +checker_address='bar@example.org' + +# address of the checked person, ping is sent here +checked_address='foo@example.org' + +# content of ping message sent to checked person +subj2checked='[pingmail] Ping!' +msg2checked='Hi!\n +\nThis is an automated mail ping from '$checker_address'. +\nRespond to show that you are still alive!' + +# content of warning message sent to checker +id_target='foo' +subj2checker='[pingmail] No recent life signs from '$id_target +reminder_time=`expr $wait_time \* 2` +msg2checker='pingmail reporting in:\n +\nNo life signs from '$id_target' for the last '$reminder_time' seconds. +\nMaybe you should give them a call to check if they are okay.' + +# mail client command reading message body from stdin and subject from parameter +mailclient_s='mail -s' + +# mailbox file to check for most recent life sign +mbox=$HOME'/mail/foo' + +# to recursively search for most recent matches to $matchstring as lifesigns +#maildir=$HOME'/mail' + +# pattern to search $maildir for recursively for lifesigns +#checked_address_escaped=`echo $checked_address | sed 's/\./\\./g'` +#matchstring='^From: .*('$checked_address_escaped'|alternate@example\.org)' diff --git a/buster/setup_scripts/setup_mail.sh b/buster/setup_scripts/setup_mail.sh index a72dc2a..09ae762 100755 --- a/buster/setup_scripts/setup_mail.sh +++ b/buster/setup_scripts/setup_mail.sh @@ -39,6 +39,14 @@ sed -i "s/REPLACE_selector_ECALPER/${selector}/g" /etc/opendkim.conf cp "${config_tree_prefix}/other_files/dovecot.sieve" /home/plom/.dovecot.sieve chown plom:plom /home/plom/.dovecot.sieve +cp "${config_tree_prefix}/other_files/fetchmailrc" /home/plom/.fetchmailrc +chown plom:plom /home/plom/.fetchmailrc +chmod 0700 /home/plom/.fetchmailrc +cp "${config_tree_prefix}/other_files/pingmailrc" /home/plom/.pingmailrc +chown plom:plom /home/plom/.pingmailrc +su -lc "cd && git clone https://plomlompom.com/repos/clone/pingmail" plom +systemctl daemon-reload + # To allow IMAPS access. echo "ssl_cert = /etc/dovecot/conf.d/99-ssl-certs.conf echo "ssl_key = > /etc/dovecot/conf.d/99-ssl-certs.conf @@ -46,19 +54,24 @@ password=$(pwgen -s 100 1) #echo 'mail_privileged_group = mail' >> /etc/dovecot/conf.d/99-mail.conf echo "plom:${password}" | chpasswd -# Get old mail data. +# Get old mail data, shutdown old postfix server. if [ "${old_server}" != "" ]; then cp "${config_tree_prefix}/setup_scripts/prepare_to_meet_server.sh" /home/plom/ - chown plom:plom /home/plom/prepare_to_meet_server.sh + #chown plom:plom /home/plom/prepare_to_meet_server.sh su -lc "./prepare_to_meet_server.sh ${old_server}" plom read -p'Hit Enter when you are done.' ignore rm /home/plom/prepare_to_meet_server.sh + su -lc "scp plom@${old_server}:.dovecot.sieve ~" plom + su -lc "scp plom@${old_server}:.fetchmailrc ~" plom + su -lc "scp plom@${old_server}:.pingmailrc ~" plom + su -lc "ssh plom@${old_server} \"su -lc 'service postfix stop'\"" plom cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/ su -lc "./mirror_dir.sh ${old_server} /home/plom/mail" plom rm /home/plom/mirror_dir.sh - su -lc "scp plom@${old_server}:.dovecot.sieve ~" plom + touch /var/mail/plom + chown plom:mail /var/mail/plom + chmod 0600 /var/mail/plom su -lc "scp plom@${old_server}:/var/mail/plom /var/mail/plom" plom - su -lc "ssh plom@${old_server} \"su -lc 'service postfix stop'\"" plom fi service opendkim restart -- 2.30.2