1require "vnd.dovecot.testsuite"; 2require "enotify"; 3require "relational"; 4require "envelope"; 5require "variables"; 6require "comparator-i;ascii-numeric"; 7 8/* 9 * Simple test 10 */ 11 12test_set "message" text: 13From: stephan@example.org 14To: nico@frop.example.org 15Subject: Frop! 16 17Klutsefluts. 18. 19; 20 21test "Simple" { 22 notify "mailto:stephan@example.org"; 23 24 if not test_result_execute { 25 test_fail "failed to execute notify"; 26 } 27 28 test_message :smtp 0; 29 30 if not header :matches "Auto-Submitted" "auto-notified*" { 31 test_fail "auto-submitted header set inappropriately"; 32 } 33 34 if not exists "X-Sieve" { 35 test_fail "x-sieve header missing from outgoing message"; 36 } 37 38 if anyof ( 39 not header :matches "x-priority" "3 *", 40 not header "importance" "normal") { 41 42 test_fail "default priority is not normal"; 43 } 44} 45 46/* 47 * Multiple recipients 48 */ 49 50test_result_reset; 51 52test_set "message" text: 53From: stephan@example.org 54To: nico@frop.example.org 55Subject: Frop! 56 57Klutsefluts. 58. 59; 60 61test "Multiple recipients" { 62 notify "mailto:timo@example.com%2cstephan@dovecot.example.net?cc=postmaster@frop.example.org&subject=Frop%20received"; 63 64 if not test_result_execute { 65 test_fail "failed to execute notify"; 66 } 67 68 test_message :smtp 0; 69 70 if not address :is "to" "timo@example.com" { 71 test_fail "first To address missing"; 72 } 73 74 if not address :is "to" "stephan@dovecot.example.net" { 75 test_fail "second To address missing"; 76 } 77 78 if not address :is "cc" "postmaster@frop.example.org" { 79 test_fail "first Cc address missing"; 80 } 81 82 if not address :count "eq" :comparator "i;ascii-numeric" "to" "2" { 83 test_fail "too many recipients in To header"; 84 } 85 86 if not address :count "eq" :comparator "i;ascii-numeric" "cc" "1" { 87 test_fail "too many recipients in Cc header"; 88 } 89 90 if not header "subject" "Frop received" { 91 test_fail "subject header set incorrectly"; 92 } 93 94 test_message :smtp 1; 95 96 if not header :matches "Auto-Submitted" "auto-notified*" { 97 test_fail "auto-submitted header not found for second message"; 98 } 99 100 test_message :smtp 2; 101 102 if not header :matches "Auto-Submitted" "auto-notified*" { 103 test_fail "auto-submitted header not found for third message"; 104 } 105} 106 107/* 108 * Duplicate recipients 109 */ 110 111test_result_reset; 112 113test_set "message" text: 114From: stephan@example.org 115To: nico@frop.example.org 116Subject: Frop! 117 118Klutsefluts. 119. 120; 121 122test "Duplicate recipients" { 123 notify "mailto:timo@example.com%2cstephan@dovecot.example.net?cc=stephan@dovecot.example.net"; 124 notify "mailto:stephan@example.org?cc=timo@example.com"; 125 126 if not test_result_execute { 127 test_fail "failed to execute notify"; 128 } 129 130 test_message :smtp 0; 131 132 if address "Cc" "stephan@dovecot.example.net" { 133 test_fail "duplicate recipient not removed from first message"; 134 } 135 136 test_message :smtp 1; 137 138 if address "Cc" "timo@example.com" { 139 test_fail "duplicate recipient not removed from second message"; 140 } 141} 142 143 144/* 145 * Notifying on automated messages 146 */ 147 148test_result_reset; 149 150test_set "message" text: 151From: stephan@example.org 152To: nico@frop.example.org 153Auto-submitted: auto-notify 154Subject: Frop! 155 156Klutsefluts. 157. 158; 159 160test "Notifying on automated messages" { 161 notify "mailto:stephan@example.org?cc=timo@example.com"; 162 163 if not test_result_execute { 164 test_fail "failed to execute notify"; 165 } 166 167 if test_message :smtp 0 { 168 test_fail "notified of auto-submitted message"; 169 } 170} 171 172/* 173 * Envelope 174 */ 175 176test_set "message" text: 177From: stephan@example.org 178To: nico@frop.example.org 179Subject: Frop! 180 181Klutsefluts. 182. 183; 184 185test_result_reset; 186 187test_set "envelope.from" "sirius@example.org"; 188test_set "envelope.to" "bertus@frop.example.org"; 189 190test "Envelope" { 191 notify "mailto:stephan@example.org?cc=timo@example.com"; 192 193 if not test_result_execute { 194 test_fail "failed to execute notify"; 195 } 196 197 test_message :smtp 0; 198 199 if not envelope :localpart :is "from" "postmaster" { 200 test_fail "envelope sender set incorrectly"; 201 } 202 203 if not envelope :is "to" "stephan@example.org" { 204 test_fail "envelope sender set incorrectly"; 205 } 206 207 test_message :smtp 1; 208 209 if not envelope :localpart :is "from" "postmaster" { 210 test_fail "envelope sender set incorrectly"; 211 } 212 213 if not envelope :is "to" "timo@example.com" { 214 test_fail "envelope sender set incorrectly"; 215 } 216} 217 218/* 219 * Envelope :from 220 */ 221 222test_set "message" text: 223From: stephan@example.org 224To: nico@frop.example.org 225Subject: Frop! 226 227Klutsefluts. 228. 229; 230 231test_set "envelope.from" "sirius@example.org"; 232test_set "envelope.to" "bertus@frop.example.org"; 233 234test_result_reset; 235 236test "Envelope :from" { 237 notify :from "nico@frop.example.org" 238 "mailto:stephan@example.org?cc=timo@example.com"; 239 240 if not test_result_execute { 241 test_fail "failed to execute notify"; 242 } 243 244 test_message :smtp 0; 245 246 if not envelope :is "from" "nico@frop.example.org" { 247 test_fail "envelope sender set incorrectly"; 248 } 249 250 if not envelope :is "to" "stephan@example.org" { 251 test_fail "envelope sender set incorrectly"; 252 } 253 254 test_message :smtp 1; 255 256 if not envelope :is "from" "nico@frop.example.org" { 257 test_fail "envelope sender set incorrectly"; 258 } 259 260 if not envelope :is "to" "timo@example.com" { 261 test_fail "envelope sender set incorrectly"; 262 } 263} 264 265/* 266 * Envelope <> 267 */ 268 269test_set "message" text: 270From: stephan@example.org 271To: nico@frop.example.org 272Subject: Frop! 273 274Klutsefluts. 275. 276; 277 278test_set "envelope.from" "<>"; 279test_set "envelope.to" "bertus@frop.example.org"; 280 281test_result_reset; 282 283test "Envelope <>" { 284 notify :from "nico@frop.example.org" 285 "mailto:stephan@example.org?cc=timo@example.com"; 286 287 if not test_result_execute { 288 test_fail "failed to execute notify"; 289 } 290 291 test_message :smtp 0; 292 293 if not envelope :is "from" "" { 294 test_fail "envelope sender set incorrectly"; 295 } 296 297 if not envelope :is "to" "stephan@example.org" { 298 test_fail "envelope recipient set incorrectly"; 299 } 300 301 test_message :smtp 1; 302 303 if not envelope :is "from" "" { 304 test_fail "envelope sender set incorrectly"; 305 } 306 307 if not envelope :is "to" "timo@example.com" { 308 test_fail "envelope recipient set incorrectly"; 309 } 310} 311 312/* 313 * Envelope config - sender 314 */ 315 316test_set "message" text: 317From: stephan@example.org 318To: nico@frop.example.org 319Subject: Frop! 320 321Klutsefluts. 322. 323; 324 325test_set "envelope.from" "sirius@example.org"; 326test_set "envelope.to" "bertus@frop.example.org"; 327 328test_config_set "sieve_notify_mailto_envelope_from" 329 "sender"; 330test_config_reload :extension "enotify"; 331test_result_reset; 332 333test "Envelope config - sender" { 334 notify :from "nico@frop.example.org" 335 "mailto:stephan@example.org?cc=timo@example.com"; 336 337 if not test_result_execute { 338 test_fail "failed to execute notify"; 339 } 340 341 test_message :smtp 0; 342 343 if not header :is "from" "nico@frop.example.org" { 344 test_fail "from set incorrectly"; 345 } 346 347 if not envelope :is "from" "sirius@example.org" { 348 test_fail "envelope sender set incorrectly"; 349 } 350 351 if not envelope :is "to" "stephan@example.org" { 352 test_fail "envelope recipient set incorrectly"; 353 } 354 355 test_message :smtp 1; 356 357 if not header :is "from" "nico@frop.example.org" { 358 test_fail "from set incorrectly"; 359 } 360 361 if not envelope :is "from" "sirius@example.org" { 362 test_fail "envelope sender set incorrectly"; 363 } 364 365 if not envelope :is "to" "timo@example.com" { 366 test_fail "envelope recipient set incorrectly"; 367 } 368} 369 370/* 371 * Envelope config - recipient 372 */ 373 374test_set "message" text: 375From: stephan@example.org 376To: nico@frop.example.org 377Subject: Frop! 378 379Klutsefluts. 380. 381; 382 383test_set "envelope.from" "sirius@example.org"; 384test_set "envelope.to" "bertus@frop.example.org"; 385 386test_config_set "sieve_notify_mailto_envelope_from" 387 "recipient"; 388test_config_reload :extension "enotify"; 389test_result_reset; 390 391test "Envelope config - recipient" { 392 notify :from "nico@frop.example.org" 393 "mailto:stephan@example.org?cc=timo@example.com"; 394 395 if not test_result_execute { 396 test_fail "failed to execute notify"; 397 } 398 399 test_message :smtp 0; 400 401 if not header :is "from" "nico@frop.example.org" { 402 test_fail "from set incorrectly"; 403 } 404 405 if not envelope :is "from" "bertus@frop.example.org" { 406 test_fail "envelope sender set incorrectly"; 407 } 408 409 if not envelope :is "to" "stephan@example.org" { 410 test_fail "envelope recipient set incorrectly"; 411 } 412 413 test_message :smtp 1; 414 415 if not header :is "from" "nico@frop.example.org" { 416 test_fail "from set incorrectly"; 417 } 418 419 if not envelope :is "from" "bertus@frop.example.org" { 420 test_fail "envelope sender set incorrectly"; 421 } 422 423 if not envelope :is "to" "timo@example.com" { 424 test_fail "envelope recipient set incorrectly"; 425 } 426} 427 428/* 429 * Envelope config - user_email 430 */ 431 432test_set "message" text: 433From: stephan@example.org 434To: nico@frop.example.org 435Subject: Frop! 436 437Klutsefluts. 438. 439; 440 441test_set "envelope.from" "sirius@example.org"; 442test_set "envelope.to" "bertus@frop.example.org"; 443 444test_config_set "sieve_notify_mailto_envelope_from" 445 "user_email"; 446test_config_set "sieve_user_email" "b.wortel@example.org"; 447test_config_reload; 448test_config_reload :extension "enotify"; 449test_result_reset; 450 451test "Envelope config - user_email" { 452 notify :from "nico@frop.example.org" 453 "mailto:stephan@example.org?cc=timo@example.com"; 454 455 if not test_result_execute { 456 test_fail "failed to execute notify"; 457 } 458 459 test_message :smtp 0; 460 461 if not header :is "from" "nico@frop.example.org" { 462 test_fail "from set incorrectly"; 463 } 464 465 if not envelope :is "from" "b.wortel@example.org" { 466 test_fail "envelope sender set incorrectly"; 467 } 468 469 if not envelope :is "to" "stephan@example.org" { 470 test_fail "envelope recipient set incorrectly"; 471 } 472 473 test_message :smtp 1; 474 475 if not header :is "from" "nico@frop.example.org" { 476 test_fail "from set incorrectly"; 477 } 478 479 if not envelope :is "from" "b.wortel@example.org" { 480 test_fail "envelope sender set incorrectly"; 481 } 482 483 if not envelope :is "to" "timo@example.com" { 484 test_fail "envelope recipient set incorrectly"; 485 } 486} 487 488/* 489 * UTF-8 addresses 490 */ 491 492test_result_reset; 493 494test_set "message" text: 495From: stephan@example.org 496To: nico@frop.example.org 497Subject: Frop! 498 499Klutsefluts. 500. 501; 502 503test "UTF-8 address" { 504 set "to" "=?utf-8?q?G=C3=BCnther?= M. Karotte <g.m.karotte@example.com>"; 505 set "cc" "Dieter T. =?utf-8?q?Stoppelr=C3=BCbe?= <d.t.stoppelruebe@example.com>"; 506 507 set :encodeurl "to_enc" "${to}"; 508 set :encodeurl "cc_enc" "${cc}"; 509 510 notify "mailto:?to=${to_enc}&cc=${cc_enc}"; 511 512 if not test_result_execute { 513 test_fail "failed to execute notify"; 514 } 515 516 test_message :smtp 0; 517 518 set "expected" "Günther M. Karotte <g.m.karotte@example.com>"; 519 if not header :is "to" "${expected}" { 520 if header :matches "to" "*" { set "decoded" "${1}"; } 521 522 test_fail text: 523to header is not encoded/decoded properly: 524expected: ${expected} 525decoded: ${decoded} 526. 527; 528 } 529 530 set "expected" "Dieter T. Stoppelrübe <d.t.stoppelruebe@example.com>"; 531 if not header :is "cc" "${expected}" { 532 if header :matches "cc" "*" { set "decoded" "${1}"; } 533 534 test_fail text: 535to header is not encoded/decoded properly: 536expected: ${expected} 537decoded: ${decoded} 538. 539; 540 } 541} 542