setup-mock-maildir (12483B)
1 #!/usr/bin/env bash 2 # mock-maildir.sh - Create realistic test mailing list 3 4 MAILDIR="./test" 5 mkdir -p "$MAILDIR"/{cur,new,tmp} 6 7 # Helper function 8 create_msg() { 9 local msgid="$1" 10 local subject="$2" 11 local from="$3" 12 local inreplyto="$4" 13 local references="$5" 14 local date="$6" 15 local body="$7" 16 17 local filename="$MAILDIR/cur/$msgid:2,S" 18 19 cat > "$filename" << EOF 20 From: $from 21 Date: $date 22 Subject: $subject 23 Message-ID: <$msgid@example.com> 24 ${inreplyto:+In-Reply-To: <$inreplyto@example.com>} 25 ${references:+References: $references} 26 27 ${body:-This is a test message about $subject.} 28 EOF 29 } 30 31 echo "Creating realistic mailing list archive..." 32 33 # Thread 1: Deep nested discussion (7 levels) 34 create_msg "001" "RFC: New authentication system" "alice@example.com" "" "" \ 35 "Mon, 13 Jan 2025 09:00:00 +0000" \ 36 "Hi all, 37 38 I'd like to propose a new authentication system for our project. 39 The current system has several limitations: 40 41 1. No support for 2FA 42 2. Sessions expire too quickly 43 3. Password reset flow is clunky 44 45 Thoughts? 46 47 --Alice" 48 49 create_msg "002" "Re: RFC: New authentication system" "bob@example.com" "001" \ 50 "<001@example.com>" "Mon, 13 Jan 2025 10:30:00 +0000" \ 51 "Great idea! I've been wanting 2FA support. 52 53 What library are you thinking of using? 54 55 --Bob" 56 57 create_msg "003" "Re: RFC: New authentication system" "alice@example.com" "002" \ 58 "<001@example.com> <002@example.com>" "Mon, 13 Jan 2025 11:15:00 +0000" \ 59 "I was looking at libauth or maybe rolling our own with TOTP. 60 61 What do you think about WebAuthn support? 62 63 --Alice" 64 65 create_msg "004" "Re: RFC: New authentication system" "charlie@example.com" "003" \ 66 "<001@example.com> <002@example.com> <003@example.com>" "Mon, 13 Jan 2025 14:20:00 +0000" \ 67 "WebAuthn would be excellent! We should definitely support it. 68 69 However, I'm concerned about backwards compatibility. 70 71 --Charlie" 72 73 create_msg "005" "Re: RFC: New authentication system" "alice@example.com" "004" \ 74 "<001@example.com> <002@example.com> <003@example.com> <004@example.com>" \ 75 "Mon, 13 Jan 2025 15:00:00 +0000" \ 76 "Good point. We can support both old and new systems during migration. 77 78 I'll draft a detailed proposal by end of week. 79 80 --Alice" 81 82 create_msg "006" "Re: RFC: New authentication system" "david@example.com" "005" \ 83 "<001@example.com> <002@example.com> <003@example.com> <004@example.com> <005@example.com>" \ 84 "Mon, 13 Jan 2025 16:45:00 +0000" \ 85 "Looking forward to it! 86 87 One more thing - what about rate limiting? 88 89 --David" 90 91 create_msg "007" "Re: RFC: New authentication system" "alice@example.com" "006" \ 92 "<001@example.com> <002@example.com> <003@example.com> <004@example.com> <005@example.com> <006@example.com>" \ 93 "Tue, 14 Jan 2025 09:00:00 +0000" \ 94 "Yes, rate limiting is in the plan. I'll include it in the RFC. 95 96 --Alice" 97 98 # Thread 1 - Branch: Side discussion from msg002 99 create_msg "008" "Re: RFC: New authentication system" "eve@example.com" "002" \ 100 "<001@example.com> <002@example.com>" "Mon, 13 Jan 2025 12:00:00 +0000" \ 101 "Has anyone considered OAuth2 integration? 102 103 This could be useful for third-party apps. 104 105 --Eve" 106 107 create_msg "009" "Re: RFC: New authentication system" "frank@example.com" "008" \ 108 "<001@example.com> <002@example.com> <008@example.com>" "Mon, 13 Jan 2025 13:30:00 +0000" \ 109 "OAuth2 is a great idea! We should support it. 110 111 I can help with the implementation if needed. 112 113 --Frank" 114 115 # Thread 2: Bug report with multiple parallel replies 116 create_msg "010" "[BUG] Segfault in parser module" "grace@example.com" "" "" \ 117 "Tue, 14 Jan 2025 10:00:00 +0000" \ 118 "Steps to reproduce: 119 1. Load large JSON file (>10MB) 120 2. Call parse_json() 121 3. Observe crash 122 123 Stack trace attached. 124 125 --Grace" 126 127 create_msg "011" "Re: [BUG] Segfault in parser module" "henry@example.com" "010" \ 128 "<010@example.com>" "Tue, 14 Jan 2025 10:30:00 +0000" \ 129 "I can reproduce this. Looking into it now. 130 131 --Henry" 132 133 create_msg "012" "Re: [BUG] Segfault in parser module" "alice@example.com" "010" \ 134 "<010@example.com>" "Tue, 14 Jan 2025 10:45:00 +0000" \ 135 "This looks like a buffer overflow in the string handling code. 136 137 I'll submit a patch. 138 139 --Alice" 140 141 create_msg "013" "Re: [BUG] Segfault in parser module" "henry@example.com" "012" \ 142 "<010@example.com> <012@example.com>" "Tue, 14 Jan 2025 11:00:00 +0000" \ 143 "You're right! The fix should be in realloc() logic. 144 145 --Henry" 146 147 # Thread 3: Orphaned reply (broken thread) 148 create_msg "014" "Re: Non-existent parent message" "iris@example.com" "999" \ 149 "<999@example.com>" "Wed, 15 Jan 2025 09:00:00 +0000" \ 150 "I agree with the points made earlier. 151 152 This is an orphaned message - parent doesn't exist! 153 154 --Iris" 155 156 # Thread 4: Very wide thread (many direct replies to root) 157 create_msg "015" "Release 2.0 planning" "alice@example.com" "" "" \ 158 "Wed, 15 Jan 2025 14:00:00 +0000" \ 159 "Let's plan the 2.0 release. What features should we include? 160 161 --Alice" 162 163 create_msg "016" "Re: Release 2.0 planning" "bob@example.com" "015" \ 164 "<015@example.com>" "Wed, 15 Jan 2025 14:15:00 +0000" \ 165 "Performance improvements!" 166 167 create_msg "017" "Re: Release 2.0 planning" "charlie@example.com" "015" \ 168 "<015@example.com>" "Wed, 15 Jan 2025 14:20:00 +0000" \ 169 "Better documentation" 170 171 create_msg "018" "Re: Release 2.0 planning" "david@example.com" "015" \ 172 "<015@example.com>" "Wed, 15 Jan 2025 14:25:00 +0000" \ 173 "Plugin system" 174 175 create_msg "019" "Re: Release 2.0 planning" "eve@example.com" "015" \ 176 "<015@example.com>" "Wed, 15 Jan 2025 14:30:00 +0000" \ 177 "Multi-language support" 178 179 create_msg "020" "Re: Release 2.0 planning" "frank@example.com" "015" \ 180 "<015@example.com>" "Wed, 15 Jan 2025 14:35:00 +0000" \ 181 "Better test coverage" 182 183 create_msg "021" "Re: Release 2.0 planning" "grace@example.com" "015" \ 184 "<015@example.com>" "Wed, 15 Jan 2025 14:40:00 +0000" \ 185 "CI/CD improvements" 186 187 # Thread 5: Multiple references (complex threading) 188 create_msg "022" "Documentation update needed" "henry@example.com" "" "" \ 189 "Thu, 16 Jan 2025 09:00:00 +0000" \ 190 "Our docs are out of date. We should update them." 191 192 create_msg "023" "Re: Documentation update needed" "iris@example.com" "022" \ 193 "<022@example.com>" "Thu, 16 Jan 2025 09:30:00 +0000" \ 194 "I can help with this." 195 196 create_msg "024" "Re: Documentation update needed" "alice@example.com" "023" \ 197 "<022@example.com> <023@example.com>" "Thu, 16 Jan 2025 10:00:00 +0000" \ 198 "Great! Let's split the work." 199 200 create_msg "025" "Re: Documentation update needed" "bob@example.com" "022" \ 201 "<022@example.com>" "Thu, 16 Jan 2025 10:15:00 +0000" \ 202 "I'll review the API docs section." 203 204 # Thread 6: Long-running discussion (spans multiple days) 205 create_msg "026" "Code style guidelines" "charlie@example.com" "" "" \ 206 "Fri, 17 Jan 2025 10:00:00 +0000" \ 207 "Should we adopt a specific code style?" 208 209 create_msg "027" "Re: Code style guidelines" "david@example.com" "026" \ 210 "<026@example.com>" "Fri, 17 Jan 2025 11:00:00 +0000" \ 211 "Yes! I suggest KNF style." 212 213 create_msg "028" "Re: Code style guidelines" "eve@example.com" "027" \ 214 "<026@example.com> <027@example.com>" "Sat, 18 Jan 2025 09:00:00 +0000" \ 215 "KNF is good but maybe too strict?" 216 217 create_msg "029" "Re: Code style guidelines" "charlie@example.com" "028" \ 218 "<026@example.com> <027@example.com> <028@example.com>" \ 219 "Mon, 20 Jan 2025 08:00:00 +0000" \ 220 "Let's vote on it next meeting." 221 222 # Thread 7: Announcement (no replies) 223 create_msg "030" "[ANNOUNCE] Server maintenance scheduled" "admin@example.com" "" "" \ 224 "Mon, 20 Jan 2025 15:00:00 +0000" \ 225 "The server will be down for maintenance on Saturday. 226 227 Expected downtime: 2 hours 228 229 --Admin" 230 231 # Thread 8: Patch submission with review 232 create_msg "031" "[PATCH] Fix memory leak in cache" "frank@example.com" "" "" \ 233 "Tue, 21 Jan 2025 09:00:00 +0000" \ 234 "This patch fixes a memory leak in the cache module. 235 236 Tested on Linux and BSD. 237 238 --Frank" 239 240 create_msg "032" "Re: [PATCH] Fix memory leak in cache" "grace@example.com" "031" \ 241 "<031@example.com>" "Tue, 21 Jan 2025 09:30:00 +0000" \ 242 "Looks good! One minor comment inline..." 243 244 create_msg "033" "Re: [PATCH] Fix memory leak in cache" "frank@example.com" "032" \ 245 "<031@example.com> <032@example.com>" "Tue, 21 Jan 2025 10:00:00 +0000" \ 246 "Updated patch attached. Thanks for the review!" 247 248 create_msg "034" "Re: [PATCH] Fix memory leak in cache" "alice@example.com" "033" \ 249 "<031@example.com> <032@example.com> <033@example.com>" \ 250 "Tue, 21 Jan 2025 10:30:00 +0000" \ 251 "Merged! Thanks Frank." 252 253 # Thread 9: Question with multiple answer branches 254 create_msg "035" "How to build on Windows?" "newbie@example.com" "" "" \ 255 "Wed, 22 Jan 2025 10:00:00 +0000" \ 256 "I'm trying to build this on Windows but getting errors. 257 258 Any help appreciated! 259 260 --Newbie" 261 262 create_msg "036" "Re: How to build on Windows?" "henry@example.com" "035" \ 263 "<035@example.com>" "Wed, 22 Jan 2025 10:30:00 +0000" \ 264 "Use MinGW. Here's what I did..." 265 266 create_msg "037" "Re: How to build on Windows?" "iris@example.com" "035" \ 267 "<035@example.com>" "Wed, 22 Jan 2025 10:45:00 +0000" \ 268 "Visual Studio works too. Check the wiki." 269 270 create_msg "038" "Re: How to build on Windows?" "newbie@example.com" "036" \ 271 "<035@example.com> <036@example.com>" "Wed, 22 Jan 2025 11:00:00 +0000" \ 272 "MinGW worked! Thanks!" 273 274 # Thread 10: Out-of-order messages (replies before parent in time) 275 create_msg "040" "Re: Future discussion" "bob@example.com" "039" \ 276 "<039@example.com>" "Thu, 23 Jan 2025 09:00:00 +0000" \ 277 "This is a reply that appears before its parent in the maildir!" 278 279 create_msg "039" "Future discussion" "alice@example.com" "" "" \ 280 "Thu, 23 Jan 2025 10:00:00 +0000" \ 281 "This message was sent after the reply (simulating delayed delivery)." 282 283 # Thread 11: Very deep thread (10 levels) 284 create_msg "041" "Deep thread test" "alice@example.com" "" "" \ 285 "Fri, 24 Jan 2025 09:00:00 +0000" "Level 0" 286 287 create_msg "042" "Re: Deep thread test" "bob@example.com" "041" \ 288 "<041@example.com>" "Fri, 24 Jan 2025 09:10:00 +0000" "Level 1" 289 290 create_msg "043" "Re: Deep thread test" "charlie@example.com" "042" \ 291 "<041@example.com> <042@example.com>" "Fri, 24 Jan 2025 09:20:00 +0000" "Level 2" 292 293 create_msg "044" "Re: Deep thread test" "david@example.com" "043" \ 294 "<041@example.com> <042@example.com> <043@example.com>" \ 295 "Fri, 24 Jan 2025 09:30:00 +0000" "Level 3" 296 297 create_msg "045" "Re: Deep thread test" "eve@example.com" "044" \ 298 "<041@example.com> <042@example.com> <043@example.com> <044@example.com>" \ 299 "Fri, 24 Jan 2025 09:40:00 +0000" "Level 4" 300 301 create_msg "046" "Re: Deep thread test" "frank@example.com" "045" \ 302 "<041@example.com> <042@example.com> <043@example.com> <044@example.com> <045@example.com>" \ 303 "Fri, 24 Jan 2025 09:50:00 +0000" "Level 5" 304 305 create_msg "047" "Re: Deep thread test" "grace@example.com" "046" \ 306 "<041@example.com> <042@example.com> <043@example.com> <044@example.com> <045@example.com> <046@example.com>" \ 307 "Fri, 24 Jan 2025 10:00:00 +0000" "Level 6" 308 309 create_msg "048" "Re: Deep thread test" "henry@example.com" "047" \ 310 "<041@example.com> <042@example.com> <043@example.com> <044@example.com> <045@example.com> <046@example.com> <047@example.com>" \ 311 "Fri, 24 Jan 2025 10:10:00 +0000" "Level 7" 312 313 create_msg "049" "Re: Deep thread test" "iris@example.com" "048" \ 314 "<041@example.com> <042@example.com> <043@example.com> <044@example.com> <045@example.com> <046@example.com> <047@example.com> <048@example.com>" \ 315 "Fri, 24 Jan 2025 10:20:00 +0000" "Level 8" 316 317 create_msg "050" "Re: Deep thread test" "alice@example.com" "049" \ 318 "<041@example.com> <042@example.com> <043@example.com> <044@example.com> <045@example.com> <046@example.com> <047@example.com> <048@example.com> <049@example.com>" \ 319 "Fri, 24 Jan 2025 10:30:00 +0000" "Level 9" 320 321 echo "" 322 echo "Test maildir created at $MAILDIR" 323 echo "Messages created: 50" 324 echo "" 325 echo "Thread scenarios included:" 326 echo " - Deep nested thread (7+ levels)" 327 echo " - Branching threads (parallel replies)" 328 echo " - Orphaned replies (missing parent)" 329 echo " - Wide threads (many direct replies)" 330 echo " - Complex References chains" 331 echo " - Out-of-order delivery" 332 echo " - Standalone announcements" 333 echo " - Very deep thread (10 levels)" 334 echo "" 335 echo "To index with notmuch:" 336 echo " notmuch new " 337 echo " notmuch show --format=sexp '*' | ./stamail "