Commit ad98cad1 ad98cad1ba758ed988a39f763ecc2ecda4eedb20 by Sergey Poznyakoff

Option -M none disables creating the mailer.

1 parent 28a860df
...@@ -49,7 +49,7 @@ sieve script interpreter. ...@@ -49,7 +49,7 @@ sieve script interpreter.
49 #include <mailutils/registrar.h> 49 #include <mailutils/registrar.h>
50 #include <mailutils/stream.h> 50 #include <mailutils/stream.h>
51 51
52 void mutil_register_all_mbox_formats(void); 52 void mutil_register_all_mbox_formats (void);
53 53
54 const char *argp_program_version = "sieve (" PACKAGE_STRING ")"; 54 const char *argp_program_version = "sieve (" PACKAGE_STRING ")";
55 55
...@@ -63,8 +63,7 @@ static char doc[] = ...@@ -63,8 +63,7 @@ static char doc[] =
63 " P - network protocols (MU_DEBUG_PROT)\n" 63 " P - network protocols (MU_DEBUG_PROT)\n"
64 " t - sieve trace (SV_DEBUG_TRACE)\n" 64 " t - sieve trace (SV_DEBUG_TRACE)\n"
65 " h - sieve header filling (SV_DEBUG_HDR_FILL)\n" 65 " h - sieve header filling (SV_DEBUG_HDR_FILL)\n"
66 " q - sieve message queries (SV_DEBUG_MSG_QUERY)\n" 66 " q - sieve message queries (SV_DEBUG_MSG_QUERY)\n";
67 ;
68 67
69 #define D_DEFAULT "TPt" 68 #define D_DEFAULT "TPt"
70 69
...@@ -85,7 +84,7 @@ static struct argp_option options[] = { ...@@ -85,7 +84,7 @@ static struct argp_option options[] = {
85 "Ticket file for mailbox authentication", 0}, 84 "Ticket file for mailbox authentication", 0},
86 85
87 {"mailer-url", 'M', "MAILER", 0, 86 {"mailer-url", 'M', "MAILER", 0,
88 "Mailer URL (defaults to \"sendmail:\")", 0}, 87 "Mailer URL (defaults to \"sendmail:\"). Use `--mailer-url none' to disable creating the mailer (it will disable reject and redirect actions as well)", 0},
89 88
90 {"debug", 'd', "FLAGS", OPTION_ARG_OPTIONAL, 89 {"debug", 'd', "FLAGS", OPTION_ARG_OPTIONAL,
91 "Debug flags (defaults to \"" D_DEFAULT "\")", 0}, 90 "Debug flags (defaults to \"" D_DEFAULT "\")", 0},
...@@ -152,31 +151,31 @@ parser (int key, char *arg, struct argp_state *state) ...@@ -152,31 +151,31 @@ parser (int key, char *arg, struct argp_state *state)
152 case 'T': 151 case 'T':
153 opts->debug_level |= MU_DEBUG_TRACE; 152 opts->debug_level |= MU_DEBUG_TRACE;
154 break; 153 break;
155 154
156 case 'P': 155 case 'P':
157 opts->debug_level |= MU_DEBUG_PROT; 156 opts->debug_level |= MU_DEBUG_PROT;
158 break; 157 break;
159 158
160 case 't': 159 case 't':
161 opts->debug_level |= SV_DEBUG_TRACE; 160 opts->debug_level |= SV_DEBUG_TRACE;
162 break; 161 break;
163 162
164 case 'h': 163 case 'h':
165 opts->debug_level |= SV_DEBUG_HDR_FILL; 164 opts->debug_level |= SV_DEBUG_HDR_FILL;
166 break; 165 break;
167 166
168 case 'q': 167 case 'q':
169 opts->debug_level |= SV_DEBUG_MSG_QUERY; 168 opts->debug_level |= SV_DEBUG_MSG_QUERY;
170 break; 169 break;
171 170
172 case 'g': 171 case 'g':
173 yydebug = 1; 172 yydebug = 1;
174 break; 173 break;
175 174
176 case 'a': 175 case 'a':
177 addrdebug = 1; 176 addrdebug = 1;
178 break; 177 break;
179 178
180 default: 179 default:
181 argp_error (state, "%c is not a valid debug flag", *arg); 180 argp_error (state, "%c is not a valid debug flag", *arg);
182 break; 181 break;
...@@ -215,17 +214,17 @@ static const char *sieve_argp_capa[] = { ...@@ -215,17 +214,17 @@ static const char *sieve_argp_capa[] = {
215 }; 214 };
216 215
217 char *sieve_license_text = 216 char *sieve_license_text =
218 " Copyright 1999 by Carnegie Mellon University\n" 217 " Copyright 1999 by Carnegie Mellon University\n"
219 " Copyright 1999,2001,2002 by Free Software Foundation\n" 218 " Copyright 1999,2001,2002 by Free Software Foundation\n"
220 "\n" 219 "\n"
221 " Permission to use, copy, modify, and distribute this software and its\n" 220 " Permission to use, copy, modify, and distribute this software and its\n"
222 " documentation for any purpose and without fee is hereby granted,\n" 221 " documentation for any purpose and without fee is hereby granted,\n"
223 " provided that the above copyright notice appear in all copies and that\n" 222 " provided that the above copyright notice appear in all copies and that\n"
224 " both that copyright notice and this permission notice appear in\n" 223 " both that copyright notice and this permission notice appear in\n"
225 " supporting documentation, and that the name of Carnegie Mellon\n" 224 " supporting documentation, and that the name of Carnegie Mellon\n"
226 " University not be used in advertising or publicity pertaining to\n" 225 " University not be used in advertising or publicity pertaining to\n"
227 " distribution of the software without specific, written prior\n" 226 " distribution of the software without specific, written prior\n"
228 " permission.\n"; 227 " permission.\n";
229 228
230 229
231 static void 230 static void
...@@ -292,13 +291,14 @@ main (int argc, char *argv[]) ...@@ -292,13 +291,14 @@ main (int argc, char *argv[])
292 291
293 /* Override license text: */ 292 /* Override license text: */
294 mu_license_text = sieve_license_text; 293 mu_license_text = sieve_license_text;
295 rc = mu_argp_parse(&argp, &argc, &argv, ARGP_IN_ORDER, sieve_argp_capa, 294 rc = mu_argp_parse (&argp, &argc, &argv, ARGP_IN_ORDER, sieve_argp_capa,
296 0, &opts); 295 0, &opts);
297 296
298 if (rc) { 297 if (rc)
298 {
299 fprintf (stderr, "arg parsing failed: %s\n", sv_strerror (rc)); 299 fprintf (stderr, "arg parsing failed: %s\n", sv_strerror (rc));
300 return 1; 300 return 1;
301 } 301 }
302 302
303 mutil_register_all_mbox_formats (); 303 mutil_register_all_mbox_formats ();
304 304
...@@ -353,29 +353,34 @@ main (int argc, char *argv[]) ...@@ -353,29 +353,34 @@ main (int argc, char *argv[])
353 } 353 }
354 if ((rc = mu_debug_set_level (debug, opts.debug_level))) 354 if ((rc = mu_debug_set_level (debug, opts.debug_level)))
355 { 355 {
356 fprintf (stderr, "mu_debug_set_level failed: %s\n", mu_errstring (rc)); 356 fprintf (stderr, "mu_debug_set_level failed: %s\n",
357 mu_errstring (rc));
357 goto cleanup; 358 goto cleanup;
358 } 359 }
359 if ((rc = mu_debug_set_print (debug, debug_print, interp))) 360 if ((rc = mu_debug_set_print (debug, debug_print, interp)))
360 { 361 {
361 fprintf (stderr, "mu_debug_set_print failed: %s\n", mu_errstring (rc)); 362 fprintf (stderr, "mu_debug_set_print failed: %s\n",
363 mu_errstring (rc));
362 goto cleanup; 364 goto cleanup;
363 } 365 }
364 } 366 }
365 367
366 /* Create a mailer. */ 368 /* Create a mailer. */
367 if ((rc = mailer_create(&mailer, opts.mailer))) 369 if (strcmp (opts.mailer, "none"))
368 {
369 fprintf (stderr, "mailer create <%s> failed: %s\n",
370 opts.mailer, mu_errstring (rc));
371 goto cleanup;
372 }
373 if (debug && (rc = mailer_set_debug (mailer, debug)))
374 { 370 {
375 fprintf (stderr, "mailer_set_debug failed: %s\n", mu_errstring (rc)); 371 if ((rc = mailer_create (&mailer, opts.mailer)))
376 goto cleanup; 372 {
373 fprintf (stderr, "mailer create <%s> failed: %s\n",
374 opts.mailer, mu_errstring (rc));
375 goto cleanup;
376 }
377 if (debug && (rc = mailer_set_debug (mailer, debug)))
378 {
379 fprintf (stderr, "mailer_set_debug failed: %s\n",
380 mu_errstring (rc));
381 goto cleanup;
382 }
377 } 383 }
378
379 /* Create, give a ticket to, and open the mailbox. */ 384 /* Create, give a ticket to, and open the mailbox. */
380 if ((rc = mailbox_create_default (&mbox, opts.mbox)) != 0) 385 if ((rc = mailbox_create_default (&mbox, opts.mbox)) != 0)
381 { 386 {
...@@ -383,7 +388,7 @@ main (int argc, char *argv[]) ...@@ -383,7 +388,7 @@ main (int argc, char *argv[])
383 opts.mbox ? opts.mbox : "default", mu_errstring (rc)); 388 opts.mbox ? opts.mbox : "default", mu_errstring (rc));
384 goto cleanup; 389 goto cleanup;
385 } 390 }
386 391
387 if (debug && (rc = mailbox_set_debug (mbox, debug))) 392 if (debug && (rc = mailbox_set_debug (mbox, debug)))
388 { 393 {
389 fprintf (stderr, "mailbox_set_debug failed: %s\n", mu_errstring (rc)); 394 fprintf (stderr, "mailbox_set_debug failed: %s\n", mu_errstring (rc));
...@@ -397,20 +402,23 @@ main (int argc, char *argv[]) ...@@ -397,20 +402,23 @@ main (int argc, char *argv[])
397 402
398 if ((rc = mailbox_get_folder (mbox, &folder))) 403 if ((rc = mailbox_get_folder (mbox, &folder)))
399 { 404 {
400 fprintf (stderr, "mailbox_get_folder failed: %s", mu_errstring (rc)); 405 fprintf (stderr, "mailbox_get_folder failed: %s",
406 mu_errstring (rc));
401 goto cleanup; 407 goto cleanup;
402 } 408 }
403 409
404 if ((rc = folder_get_authority (folder, &auth))) 410 if ((rc = folder_get_authority (folder, &auth)))
405 { 411 {
406 fprintf (stderr, "folder_get_authority failed: %s", mu_errstring (rc)); 412 fprintf (stderr, "folder_get_authority failed: %s",
413 mu_errstring (rc));
407 goto cleanup; 414 goto cleanup;
408 } 415 }
409 416
410 /* Authentication-less folders don't have authorities. */ 417 /* Authentication-less folders don't have authorities. */
411 if (auth && (rc = authority_set_ticket (auth, ticket))) 418 if (auth && (rc = authority_set_ticket (auth, ticket)))
412 { 419 {
413 fprintf (stderr, "authority_set_ticket failed: %s", mu_errstring (rc)); 420 fprintf (stderr, "authority_set_ticket failed: %s",
421 mu_errstring (rc));
414 goto cleanup; 422 goto cleanup;
415 } 423 }
416 } 424 }
...@@ -445,11 +453,14 @@ main (int argc, char *argv[]) ...@@ -445,11 +453,14 @@ main (int argc, char *argv[])
445 if ((rc = mailbox_get_message (mbox, msgno, &msg)) != 0) 453 if ((rc = mailbox_get_message (mbox, msgno, &msg)) != 0)
446 { 454 {
447 fprintf (stderr, "get message on %s (msg %d) failed: %s\n", 455 fprintf (stderr, "get message on %s (msg %d) failed: %s\n",
448 opts.mbox ? opts.mbox : "default", msgno, mu_errstring (rc)); 456 opts.mbox ? opts.mbox : "default", msgno,
457 mu_errstring (rc));
449 goto cleanup; 458 goto cleanup;
450 } 459 }
451 460
452 rc = sv_script_execute (script, msg, ticket, debug, mailer, opts.no_actions); 461 rc =
462 sv_script_execute (script, msg, ticket, debug, mailer,
463 opts.no_actions);
453 464
454 if (rc) 465 if (rc)
455 { 466 {
...@@ -469,20 +480,20 @@ cleanup: ...@@ -469,20 +480,20 @@ cleanup:
469 int e; 480 int e;
470 481
471 /* A message won't be marked deleted unless the script executed 482 /* A message won't be marked deleted unless the script executed
472 succesfully on it, so we always do an expunge, it will delete 483 succesfully on it, so we always do an expunge, it will delete
473 any messages that were marked DELETED even if execution failed 484 any messages that were marked DELETED even if execution failed
474 on a later message. */ 485 on a later message. */
475 if ((e = mailbox_expunge (mbox)) != 0) 486 if ((e = mailbox_expunge (mbox)) != 0)
476 fprintf (stderr, "expunge on %s failed: %s\n", 487 fprintf (stderr, "expunge on %s failed: %s\n",
477 opts.mbox ? opts.mbox : "default", mu_errstring (e)); 488 opts.mbox ? opts.mbox : "default", mu_errstring (e));
478 489
479 if(e && !rc) 490 if (e && !rc)
480 rc = e; 491 rc = e;
481 } 492 }
482 493
483 mailbox_close (mbox); 494 mailbox_close (mbox);
484 mailbox_destroy (&mbox); 495 mailbox_destroy (&mbox);
485 mu_debug_destroy(&debug, interp); 496 mu_debug_destroy (&debug, interp);
486 sv_script_free (&script); 497 sv_script_free (&script);
487 sv_interp_free (&interp); 498 sv_interp_free (&interp);
488 499
...@@ -503,4 +514,3 @@ mutil_register_all_mbox_formats (void) ...@@ -503,4 +514,3 @@ mutil_register_all_mbox_formats (void)
503 list_append (bookie, sendmail_record); 514 list_append (bookie, sendmail_record);
504 list_append (bookie, smtp_record); 515 list_append (bookie, smtp_record);
505 } 516 }
506
......