imap-download: fiddle with permissions again

This commit is contained in:
Starbeamrainbowlabs 2021-05-26 22:58:53 +01:00
parent eab364ab09
commit 27f6f4a575
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -73,16 +73,6 @@ log_msg() {
mkdir -p "${dir_newmail}"; mkdir -p "${dir_newmail}";
chown -R "${fetchmail_uid}:${fetchmail_gid}" "${dir_mail_root}"; chown -R "${fetchmail_uid}:${fetchmail_gid}" "${dir_mail_root}";
# Moves an attachment to the output directory as the target uid/gid.
# chowns the file before moving.
# $1 The path to the file to move.
move_attachment() {
local filename="${1}";
chown "${TARGET_UID}:${TARGET_GID}" "${filename}";
ls -lah "${filename}";
run_as_user "${TARGET_UID}" "${TARGET_GID}" mv "${filename}" "${target_dir}";
}
do_attachments() { do_attachments() {
while :; do # : = infinite loop while :; do # : = infinite loop
@ -104,11 +94,16 @@ do_attachments() {
rm "${filepath_temp}"; rm "${filepath_temp}";
find "${temp_dir}" -iname '*.desc' -delete; find "${temp_dir}" -iname '*.desc' -delete;
chown -R "${TARGET_UID}:${TARGET_GID}" "${temp_dir}";
chmod -R a=rX,ug+w "${temp_dir}";
ls -lahR "${temp_dir}";
# Move the attachment files to the output directory # Move the attachment files to the output directory
while read -r attachment; do while read -r attachment; do
log_msg "Extracted attachment ${attachment}"; log_msg "Extracted attachment ${attachment}";
chmod 0775 "${attachment}"; chmod 0775 "${attachment}";
move_attachment "${attachment}"; run_as_user "${TARGET_UID}" "${TARGET_GID}" mv "${attachment}" "${target_dir}";
done < <(find "${temp_dir}" -type f); done < <(find "${temp_dir}" -type f);
done < <(find "${dir_newmail}" -type f); done < <(find "${dir_newmail}" -type f);
done done