How gigachad80/mailansh works
Project Type and Purpose
• Mailansh is a Go-based command-line OSINT utility for extracting contributor emails from Git repositories across multiple hosting platforms (GitHub, GitLab, Gitea, Bitbucket).
• It emphasizes high performance via concurrent processing, advanced filtering, smart deduplication, and multiple output formats.
File Structure Analysis
• cmd/mailansh/main.go: CLI entrypoint—parses flags, loads configuration, initializes components, orchestrates workflow.
• internal/config: Flag and configuration parsing.
• pkg/platform: Abstraction over multiple Git hosting platforms (URL patterns, platform-specific filters).
• pkg/git: Wrappers around the Git CLI for cloning and repository operations.
• pkg/extractor: Core extraction engine, split into:
• commit.go (linear git-log extraction)
• patch.go (patch scanning, uses worker pool)
• pkg/contributor: Thread-safe manager for deduplicating, filtering, and categorizing emails.
• pkg/output: Formatting and writing results (table, CSV, text).
• pkg/progress: Real-time progress reporting.
Key Architectural Patterns
• Worker Pool Pattern: Eight goroutines process patch data concurrently.
• Dual Extraction Pipeline:
• Pipeline A: Serial commit-history scanning.
• Pipeline B: Parallel patch content analysis.
• Thread Safety: Contributor manager uses mutexes to avoid race conditions.
• Streaming & Cleanup: Intermediate data is streamed and cleaned up to minimize memory footprint.
• Context-Aware Execution: Cancellation and timeouts propagate through extractors.
Main Components
• CLI Layer
• Flag Parser (internal/config)
• Configuration Loader
• Platform Resolver (pkg/platform)
• Determines repository URL patterns & any platform-specific logic.
• Git Layer (pkg/git)
• Clone or fetch repository via Git CLI.
• Extraction Engine (pkg/extractor)
• CommitLog Extractor (sequential)
• Patch Extractor with Worker Pool (concurrent)
• Coordination component that fans out commit IDs to patch workers.
• Contributor Manager (pkg/contributor)
• Central aggregator, deduplicator, filter engine.
• Progress Reporter (pkg/progress)
• Subscribes to both extraction pipelines for real-time updates.
• Renders final results to stdout or writes to CSV/text file.
Relationships and Data Flows
• User ⇒ CLI Layer: starts process with flags and repo URL.
• CLI Layer ⇒ Platform Resolver ⇒ Git Layer: clones repo to local workspace.
• Git Layer ⇒ Extraction Engine: scans commits ⇒ emits commit IDs and diffs.
• Extraction Engine ⇒ Contributor Manager: pushes discovered emails.
• Extraction Engine & Contributor Manager ⇒ Progress Reporter: updates are published.
• Contributor Manager ⇒ Output Formatter ⇒ User: final formatted output.
• Errors and cancellation signals propagate back through context.