#!/bin/sh # # Verify that the exact message owned by bongoqueue reaches bongostore without # byte changes. The queue trace header is intentionally included in the # comparison: QRETR is the source of truth, not the pre-queue input file. set -eu user=${1:-stqqueue} sender=${2:-stq02@bongo.test} queue_tool=${BONGO_QUEUE_TOOL:-/usr/bin/bongo-queuetool} store_tool=${BONGO_STORE_TOOL:-/usr/bin/bongo-storetool} run_as=${BONGO_TEST_RUN_AS:-bongo} if [ "$(id -un)" = "$run_as" ]; then as_bongo= else as_bongo="sudo -n -u $run_as" fi work=$(mktemp -d "${TMPDIR:-/tmp}/bongo-stq02.XXXXXX") chmod 0755 "$work" queue_id= cleanup() { if [ -n "$queue_id" ]; then $as_bongo "$queue_tool" delete "$queue_id" >/dev/null 2>&1 || true fi rm -rf "$work" } trap cleanup EXIT HUP INT TERM # Keep this RFC 5322 message deterministic and CRLF-clean. The UTF-8 and long # folded line catch text-mode, encoding, and accidental line-ending changes. printf '%s\r\n' \ "From: STQ-02 <$sender>" \ "To: $user@bongo.test" \ "Subject: STQ-02 byte preservation äöü" \ "Date: Thu, 23 Jul 2026 12:34:56 +0200" \ "Message-ID: " \ "MIME-Version: 1.0" \ "Content-Type: text/plain; charset=UTF-8" \ "Content-Transfer-Encoding: 8bit" \ "X-STQ-02-Fold: first;" \ " second; third" \ "" \ "line one" \ ".dot line must not be SMTP-unescaped here" \ "Grüße aus dem Queue-zu-Store-Test." >"$work/input.eml" chmod 0644 "$work/input.eml" $as_bongo "$store_tool" -u "$user" \ document-list /mail/INBOX >"$work/before" queue_id=$($as_bongo "$queue_tool" hold-local "$work/input.eml") case "$queue_id" in 999-*) ;; *) echo "STQ-02: unexpected held queue ID: $queue_id" >&2 exit 1 ;; esac $as_bongo "$queue_tool" message "$queue_id" >"$work/queue.eml" $as_bongo "$queue_tool" deliver-local \ "$queue_id" "$sender" "$user" INBOX $as_bongo "$store_tool" -u "$user" \ document-list /mail/INBOX >"$work/after" awk '{ print $1 }' "$work/before" | sort -u >"$work/before.ids" awk '{ print $1 }' "$work/after" | sort -u >"$work/after.ids" comm -13 "$work/before.ids" "$work/after.ids" >"$work/new.ids" count=$(wc -l <"$work/new.ids") if [ "$count" -ne 1 ]; then echo "STQ-02: expected one new Store object, found $count" >&2 diff -u "$work/before" "$work/after" >&2 || true exit 1 fi document=$(sed -n '1p' "$work/new.ids") $as_bongo "$store_tool" -u "$user" \ document-get "$document" - >"$work/store.eml" if ! cmp -s "$work/queue.eml" "$work/store.eml"; then echo "STQ-02: Queue and Store message bytes differ" >&2 cmp -l "$work/queue.eml" "$work/store.eml" | sed -n '1,20p' >&2 exit 1 fi queue_sha=$(sha256sum "$work/queue.eml" | awk '{ print $1 }') store_sha=$(sha256sum "$work/store.eml" | awk '{ print $1 }') queue_size=$(wc -c <"$work/queue.eml") store_size=$(wc -c <"$work/store.eml") printf 'STQ-02 PASS queue=%s document=%s bytes=%s sha256=%s store-bytes=%s store-sha256=%s\n' \ "$queue_id" "$document" "$queue_size" "$queue_sha" \ "$store_size" "$store_sha"