From 9bace6ecdcbcf0dfe9022349ed07c813f040e49d Mon Sep 17 00:00:00 2001 From: Alnotz Date: Tue, 24 Dec 2024 17:23:07 +0100 Subject: [PATCH] Import from Zimbra to Thunderbird --- Bash/zimbra2thunderbird.sh | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Bash/zimbra2thunderbird.sh diff --git a/Bash/zimbra2thunderbird.sh b/Bash/zimbra2thunderbird.sh new file mode 100644 index 0000000..b91ee93 --- /dev/null +++ b/Bash/zimbra2thunderbird.sh @@ -0,0 +1,46 @@ +#!/usr/bin/bash + +if [ ! $# = 3 ] +then + echo 'Usage : zimbra2thunderbird.sh PROFILE_DIR ARCHIVE FOLDER_NAME' + echo + echo 'PROFILE_DIR Thunderbird Profile directory' + echo 'ARCHIVE Zip over Tarball archive (Zimbra EML files)' + echo "FOLDER_NAME E-mail folder name" + exit 0 +fi + +declare -r ROOT_DIR="${1}/Mail/Local Folders" +declare -r TMP_DIR="/tmp/zimbra2thunderbird" + +# from_line META_FILE +function from_line() +( + declare -r FILE="$1" + declare -r ADDRESS=$( grep -o '"sender":"[^,"]*' "${FILE}" | sed 's/"sender":"//;s/\s//' ) + declare -r SECONDES=$( grep -o '"date":[0-9]*' "${FILE}" | sed 's/"date"://' ) + declare -r DATE=$( LANG=C date -d "@${SECONDES}" '+%a %b %d %H:%M:%S %Y' ) + echo "From ${ADDRESS} ${DATE}" +) + +mkdir "$TMP_DIR" +cd "$TMP_DIR" || exit 1 + +tar -xzf "$2" + +touch "${ROOT_DIR}/${3}" +mkdir "${ROOT_DIR}/${3}.sbd" +for folder in * +do + touch "${folder}.mbox" + for eml in ${folder}/*.eml + do + from_line "${eml}.meta" + cat "${eml}" + echo + done >> "${folder}.mbox" + mv "${folder}.mbox" "${ROOT_DIR}/${3}.sbd/${folder}" +done + +cd || exit 1 +rm -rf "$TMP_DIR"