#!/bin/bash # Mock himalaya command for testing # Controlled by environment variables for different test scenarios # Mock less command that doesn't wait for input in tests if [ -z "$MOCK_LESS_INTERACTIVE" ]; then # In test mode, just output directly without paging alias less='cat' fi # Default test data - matches real himalaya output format DEFAULT_ENVELOPE_LIST="| ID | FLAGS | SUBJECT | FROM | DATE | |------|-------|---------------------------------------------------------------------------------------------------|------------------------------|------------------------| | 1 | | Important Meeting | john@example.com | 2024-01-15 10:00+00:00| | 5 | * | Project Update | sarah@company.com | 2024-01-14 15:30+00:00| | 7 | | Weekly Standup | team@startup.com | 2024-01-13 09:00+00:00| | 10 | | Contract Review | client@business.com | 2024-01-12 14:00+00:00|" DEFAULT_MESSAGE_CONTENT="From: test@example.com To: user@example.com Subject: Test Message Date: 2024-01-15 This is a test message content for testing purposes." # Handle different commands case "$1" in "envelope") case "$2" in "list") if [ -n "$MOCK_ENVELOPE_LIST" ]; then echo "$MOCK_ENVELOPE_LIST" elif [ "$MOCK_EMPTY_INBOX" = "true" ]; then echo "" elif [ "$MOCK_HIMALAYA_FAIL" = "true" ]; then echo "Error: Unable to connect to server" >&2 exit 1 else echo "$DEFAULT_ENVELOPE_LIST" fi ;; esac ;; "message") case "$2" in "read") message_id="$3" if [ "$MOCK_HIMALAYA_FAIL" = "true" ]; then echo "Error: Unable to read message $message_id" >&2 exit 1 elif [ -n "$MOCK_INVALID_MESSAGE_ID" ] && [ "$message_id" = "$MOCK_INVALID_MESSAGE_ID" ]; then echo "Error: Message $message_id not found" >&2 exit 1 elif [ -n "$MOCK_ENVELOPE_LIST" ]; then # Check if the message ID exists in our envelope list # Handle both old tab-separated format and new table format if echo "$MOCK_ENVELOPE_LIST" | grep -q "^$message_id " || echo "$MOCK_ENVELOPE_LIST" | grep -q "^| $message_id "; then if [ -n "$MOCK_MESSAGE_CONTENT" ]; then echo "$MOCK_MESSAGE_CONTENT" else echo "$DEFAULT_MESSAGE_CONTENT" fi else echo "Error: Message $message_id not found" >&2 exit 1 fi else if [ -n "$MOCK_MESSAGE_CONTENT" ]; then echo "$MOCK_MESSAGE_CONTENT" else echo "$DEFAULT_MESSAGE_CONTENT" fi fi ;; "delete") message_id="$3" if [ "$MOCK_HIMALAYA_FAIL" = "true" ]; then echo "Error: Unable to delete message $message_id" >&2 exit 1 else echo "Message $message_id deleted successfully" fi ;; "move") folder="$3" message_id="$4" if [ "$MOCK_HIMALAYA_FAIL" = "true" ]; then echo "Error: Unable to move message $message_id to $folder" >&2 exit 1 else echo "Message $message_id moved to $folder successfully" fi ;; esac ;; *) echo "Mock himalaya: Unknown command $1" >&2 exit 1 ;; esac