mail2couch/test/test-wildcard-patterns.sh
Ole-Morten Duesund 357cd06264 feat: implement comprehensive wildcard folder selection and keyword filtering
## Wildcard Folder Selection
- Add support for wildcard patterns (`*`, `?`, `[abc]`) using filepath.Match
- Implement special case: `"*"` selects ALL available folders
- Support for complex include/exclude pattern combinations
- Maintain backwards compatibility with exact string matching
- Enable subfolder pattern matching (e.g., `Work/*`, `*/Drafts`)

## Keyword Filtering
- Add SubjectKeywords, SenderKeywords, RecipientKeywords to MessageFilter config
- Implement case-insensitive keyword matching across message fields
- Support multiple keywords per filter type with inclusive OR logic
- Add ShouldProcessMessage method for message-level filtering

## Enhanced Test Environment
- Create comprehensive wildcard pattern test scenarios
- Add 12 test folders covering various pattern types: Work/*, Important/*, Archive/*, exact matches
- Implement dedicated wildcard test script (test-wildcard-patterns.sh)
- Update test configurations to demonstrate real-world wildcard usage patterns
- Enhance test data generation with folder-specific messages for validation

## Documentation
- Create FOLDER_PATTERNS.md with comprehensive wildcard examples and use cases
- Update CLAUDE.md to reflect all implemented features and current status
- Enhance test README with detailed wildcard pattern explanations
- Provide configuration examples for common email organization scenarios

## Message Origin Tracking
- Verify all messages in CouchDB properly tagged with origin folder in `mailbox` field
- Maintain per-account database isolation for better organization
- Document ID format: `{folder}_{uid}` ensures uniqueness across folders

Key patterns supported:
- `["*"]` - All folders (with excludes)
- `["Work*", "Important*"]` - Prefix matching
- `["Work/*", "Archive/*"]` - Subfolder patterns
- `["INBOX", "Sent"]` - Exact matches
- Complex include/exclude combinations

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-01 17:24:02 +02:00

137 lines
No EOL
4 KiB
Bash
Executable file

#!/bin/bash
# Test script to validate wildcard folder pattern functionality
# This script tests the various wildcard patterns against the test environment
set -e
echo "🧪 Testing Wildcard Folder Pattern Functionality"
echo "================================================"
# Make sure we're in the right directory
cd "$(dirname "$0")/.."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to run mail2couch with a specific config and capture output
run_test() {
local test_name="$1"
local config_file="$2"
local max_messages="$3"
echo -e "\n${BLUE}Testing: $test_name${NC}"
echo "Config: $config_file"
echo "Max messages: $max_messages"
echo "----------------------------------------"
# Run mail2couch and capture output
cd go
if ./mail2couch -config "../test/$config_file" -max-messages "$max_messages" 2>&1; then
echo -e "${GREEN}✅ Test completed successfully${NC}"
else
echo -e "${RED}❌ Test failed${NC}"
return 1
fi
cd ..
}
# Function to check if containers are running
check_containers() {
echo "🔍 Checking if test containers are running..."
if ! podman ps | grep -q "greenmail"; then
echo -e "${RED}❌ GreenMail container not running${NC}"
echo "Please run: cd test && ./start-test-env.sh"
exit 1
fi
if ! podman ps | grep -q "couchdb"; then
echo -e "${RED}❌ CouchDB container not running${NC}"
echo "Please run: cd test && ./start-test-env.sh"
exit 1
fi
echo -e "${GREEN}✅ Test containers are running${NC}"
}
# Function to populate test data
populate_test_data() {
echo "📧 Populating test data..."
cd test
if python3 populate-greenmail.py; then
echo -e "${GREEN}✅ Test data populated successfully${NC}"
else
echo -e "${RED}❌ Failed to populate test data${NC}"
exit 1
fi
cd ..
}
# Function to build the application
build_app() {
echo "🔨 Building mail2couch..."
cd go
if go build -o mail2couch .; then
echo -e "${GREEN}✅ Build successful${NC}"
else
echo -e "${RED}❌ Build failed${NC}"
exit 1
fi
cd ..
}
# Main test execution
main() {
echo "Starting wildcard pattern tests..."
# Pre-test checks
check_containers
build_app
populate_test_data
# Wait a moment for test data to be fully ready
echo "⏳ Waiting for test data to settle..."
sleep 3
# Test 1: Wildcard all folders (*)
echo -e "\n${YELLOW}Test 1: Wildcard All Folders Pattern (*)${NC}"
echo "Expected: Should process all folders except Drafts and Trash"
run_test "Wildcard All Folders" "config-test.json" 3
# Test 2: Work pattern (Work*)
echo -e "\n${YELLOW}Test 2: Work Pattern (Work*)${NC}"
echo "Expected: Should process Work/Projects, Work/Archive but not Work/Temp (excluded by *Temp*)"
run_test "Work Pattern" "config-test.json" 3
# Test 3: Specific folders only
echo -e "\n${YELLOW}Test 3: Specific Folders Only${NC}"
echo "Expected: Should only process INBOX, Sent, and Personal folders"
run_test "Specific Folders" "config-test.json" 3
# Test 4: Advanced wildcard examples
echo -e "\n${YELLOW}Test 4: Advanced Wildcard Examples${NC}"
echo "Expected: Various complex patterns should work correctly"
run_test "Advanced Patterns" "config-wildcard-examples.json" 2
echo -e "\n${GREEN}🎉 All wildcard pattern tests completed!${NC}"
echo ""
echo "To verify results, check the CouchDB databases:"
echo " http://localhost:5984/_utils"
echo ""
echo "Expected databases should be created for each account:"
echo " - wildcard_all_folders_test"
echo " - work_pattern_test"
echo " - specific_folders_only"
echo ""
echo "Each database should contain documents with 'mailbox' field showing origin folder."
}
# Run main function if executed directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi