package main import ( "bufio" "fmt" "log" "os" "os/exec" "runtime" "strconv" "strings" ) type OrganizationStep struct { Name string Description string Command string Args []string } func main() { if len(os.Args) < 2 { fmt.Println("Usage: go run organize.go ") fmt.Println(" csv_file: path to CSV file from main.go") fmt.Println("\nThis interactive tool will help you organize your Gmail inbox step by step.") os.Exit(1) } csvFile := os.Args[1] fmt.Printf("\n๐ŸŽฏ GMAIL INBOX ORGANIZATION WIZARD\n") fmt.Printf("===================================\n\n") fmt.Printf("This tool will guide you through organizing your Gmail inbox using the analysis\n") fmt.Printf("from your exported email data (%s).\n\n", csvFile) // Step 1: Run analysis fmt.Printf("STEP 1: Analyzing your emails...\n") analysisFile := runAnalysis(csvFile) // Step 2: Show summary and get user preference fmt.Printf("\nSTEP 2: Choose your organization approach...\n") approach := getUserApproach() // Step 3: Execute organization plan fmt.Printf("\nSTEP 3: Executing organization plan...\n") executeOrganizationPlan(analysisFile, approach) fmt.Printf("\nโœ… Organization complete!\n") fmt.Printf("\nNext steps:\n") fmt.Printf("1. Review the generated Gmail filters and search queries\n") fmt.Printf("2. Apply them gradually to your Gmail account\n") fmt.Printf("3. Monitor the results and adjust as needed\n") fmt.Printf("4. Run this tool periodically to maintain organization\n") } func runAnalysis(csvFile string) string { fmt.Printf("Running email analysis...\n") analysisFile := strings.TrimSuffix(csvFile, ".csv") + "_analysis.json" cmd := exec.Command("go", "run", "analyze.go", csvFile, "json") output, err := cmd.Output() if err != nil { log.Fatalf("Error running analysis: %v", err) } // Save analysis to file err = os.WriteFile(analysisFile, output, 0644) if err != nil { log.Fatalf("Error saving analysis: %v", err) } // Also show summary cmd = exec.Command("go", "run", "analyze.go", csvFile, "summary") output, err = cmd.Output() if err != nil { log.Printf("Warning: Could not generate summary: %v", err) } else { fmt.Printf("%s\n", output) } return analysisFile } func getUserApproach() string { fmt.Printf("\nChoose your organization approach:\n\n") fmt.Printf("1. ๐Ÿงน AGGRESSIVE CLEANUP\n") fmt.Printf(" - Focus on deleting and archiving old emails\n") fmt.Printf(" - Best for: Very cluttered inboxes, storage concerns\n") fmt.Printf(" - Risk: Moderate (might delete emails you want to keep)\n\n") fmt.Printf("2. ๐Ÿ“‹ FILTER-FOCUSED\n") fmt.Printf(" - Focus on creating Gmail filters for future organization\n") fmt.Printf(" - Best for: Maintaining organization going forward\n") fmt.Printf(" - Risk: Low (doesn't delete anything)\n\n") fmt.Printf("3. ๐ŸŽฏ BALANCED APPROACH\n") fmt.Printf(" - Combination of cleanup and filters\n") fmt.Printf(" - Best for: Most users\n") fmt.Printf(" - Risk: Low to moderate\n\n") fmt.Printf("4. ๐Ÿ“Š ANALYSIS ONLY\n") fmt.Printf(" - Just generate reports and recommendations\n") fmt.Printf(" - Best for: Understanding your email patterns first\n") fmt.Printf(" - Risk: None\n\n") for { fmt.Printf("Enter your choice (1-4): ") reader := bufio.NewReader(os.Stdin) input, _ := reader.ReadString('\n') choice := strings.TrimSpace(input) switch choice { case "1": return "aggressive" case "2": return "filters" case "3": return "balanced" case "4": return "analysis" default: fmt.Printf("Invalid choice. Please enter 1, 2, 3, or 4.\n") } } } func executeOrganizationPlan(analysisFile, approach string) { switch approach { case "aggressive": executeAggressiveCleanup(analysisFile) case "filters": executeFilterFocus(analysisFile) case "balanced": executeBalancedApproach(analysisFile) case "analysis": executeAnalysisOnly(analysisFile) } } func executeAggressiveCleanup(analysisFile string) { fmt.Printf("\n๐Ÿงน AGGRESSIVE CLEANUP APPROACH\n") fmt.Printf("==============================\n\n") // Generate cleanup recommendations fmt.Printf("Generating cleanup recommendations...\n") runCommand("go", "run", "cleanup.go", analysisFile, "detailed") fmt.Printf("\nโš ๏ธ IMPORTANT:\n") fmt.Printf("1. Review the deletion recommendations carefully\n") fmt.Printf("2. Start with 'Low risk' deletions first\n") fmt.Printf("3. Test on a small batch before doing bulk operations\n") fmt.Printf("4. Consider creating a backup label before deleting\n") // Also generate filters for future fmt.Printf("\nGenerating filters to prevent future buildup...\n") runCommand("go", "run", "filters.go", analysisFile, "filters") } func executeFilterFocus(analysisFile string) { fmt.Printf("\n๐Ÿ“‹ FILTER-FOCUSED APPROACH\n") fmt.Printf("==========================\n\n") fmt.Printf("Generating Gmail filter recommendations...\n") runCommand("go", "run", "filters.go", analysisFile, "all") fmt.Printf("\n๐Ÿ’ก IMPLEMENTATION TIPS:\n") fmt.Printf("1. Start with high-impact filters (newsletters, social media)\n") fmt.Printf("2. Test each filter on a small subset first\n") fmt.Printf("3. Create labels before creating filters\n") fmt.Printf("4. Use 'Skip inbox' for non-urgent categories\n") } func executeBalancedApproach(analysisFile string) { fmt.Printf("\n๐ŸŽฏ BALANCED APPROACH\n") fmt.Printf("====================\n\n") // First show cleanup for low-risk items fmt.Printf("PHASE 1: Safe cleanup recommendations\n") fmt.Printf("------------------------------------\n") runCommand("go", "run", "cleanup.go", analysisFile, "summary") fmt.Printf("\nPHASE 2: Gmail filter setup\n") fmt.Printf("---------------------------\n") runCommand("go", "run", "filters.go", analysisFile, "filters") fmt.Printf("\n๐Ÿ“‹ RECOMMENDED ORDER:\n") fmt.Printf("1. Create Gmail filters first (prevents future clutter)\n") fmt.Printf("2. Apply low-risk deletions\n") fmt.Printf("3. Set up bulk archive operations\n") fmt.Printf("4. Review and unsubscribe from high-volume senders\n") } func executeAnalysisOnly(analysisFile string) { fmt.Printf("\n๐Ÿ“Š ANALYSIS REPORT\n") fmt.Printf("==================\n\n") fmt.Printf("Email Analysis Summary:\n") fmt.Printf("----------------------\n") runCommand("go", "run", "analyze.go", strings.Replace(analysisFile, "_analysis.json", ".csv", 1), "summary") fmt.Printf("\nDetailed Cleanup Potential:\n") fmt.Printf("--------------------------\n") runCommand("go", "run", "cleanup.go", analysisFile, "summary") fmt.Printf("\nGmail Search Queries:\n") fmt.Printf("--------------------\n") runCommand("go", "run", "filters.go", analysisFile, "queries") fmt.Printf("\n๐Ÿ’ก NEXT STEPS:\n") fmt.Printf("Run this tool again with a different approach when you're ready to take action.\n") } func runCommand(name string, args ...string) { cmd := exec.Command(name, args...) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr err := cmd.Run() if err != nil { fmt.Printf("Warning: Command failed: %v\n", err) } } func openURL(url string) error { var cmd string var args []string switch runtime.GOOS { case "windows": cmd = "cmd" args = []string{"/c", "start"} case "darwin": cmd = "open" default: // "linux", "freebsd", "openbsd", "netbsd" cmd = "xdg-open" } args = append(args, url) return exec.Command(cmd, args...).Start() }