Newer
Older
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
#
# GPG Encrypt a Maildir using gpgit.pl
#
# License
# =======
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
USERNAME=$ADMIN_USER
fi
MAIL_DIR=/home/$USERNAME/Maildir
EMAIL_ADDRESS=$USERNAME@$HOSTNAME
# Does this key exist?
echo $"A GPG key for $EMAIL_ADDRESS could not be found!"
exit 0
fi
# Find all files in the Maildir specified.
echo $"Calling find"
find "$MAIL_DIR" -type f -regex '.*/\(cur\|new\)/.*' "$4"|while read -r line; do
gpgit.pl --encrypt-mode prefer-inline "$EMAIL_ADDRESS" "/tmp/msg_$USERNAME"
# Check to see if there are differences between the existing
# Maildir file and what was created by gpgit.pl
diff -qa "$line" "/tmp/msg_$USERNAME" > /dev/null 2>&1;
if [ $? -gt 0 ]; then
# Preserve timestamps, set ownership.
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
chmod 600 "/tmp/msg_$USERNAME"
touch "/tmp/msg_$USERNAME" --reference="$line"
# Unlink the original Maildir message
unlink "$line"
# Strip message sizes, retain experimental flags
# and status flags, and copy the file over.
STRIPSIZES=$(/bin/echo "$line"|/bin/sed -e "s/W=[[:digit:]]*//" -e "s/S=[[:digit:]]*//" -e "s/,,//" -e "s/,:2/:2/")
cp -av "/tmp/msg_$USERNAME" "$STRIPSIZES"
#Indexes must be rebuilt, weve modified Maildir.
touch "/tmp/rebuild_index_$USERNAME"
else
echo $"Not copying, no differences between /tmp/msg_$USERNAME and $line"
fi
# Remove the temporary file
unlink "/tmp/msg_$USERNAME"
done
# Remove Dovecot index and uids for regeneration.
if [ -f "/tmp/rebuild_index_$USERNAME" ]; then
echo $"Removing Dovecot indexes and uids"
find "$MAIL_DIR" -type f -regex '.*\(dovecot-\|dovecot\.\|\.uidvalidity\).*' -delete
# Remove the temporary file
unlink "/tmp/rebuild_index_$USERNAME"
else
echo -n $"No messages found needing GPG encryption, not"
echo $"removing Dovecot indexes and UIDs."
fi
exit 0