diff -r 30113bfbe723 -r b3afb9f1e801 commands/vdeliver.cc --- a/commands/vdeliver.cc Sun Jan 20 00:12:17 2008 +0100 +++ b/commands/vdeliver.cc Sun Jan 20 00:22:09 2008 +0100 @@ -1,4 +1,4 @@ -// Copyright (C) 1999,2000 Bruce Guenter +// Copyright (C) 1999,2000,2005 Bruce Guenter // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -23,7 +23,7 @@ #include "ac/wait.h" #include #include "fdbuf/fdbuf.h" -#include "cli/cli.h" +#include "cli++/cli++.h" #include "vcommand.h" #include "misc/itoa.h" #include "misc/stat_fns.h" @@ -39,6 +39,8 @@ static int addrpline = true; static int adddtline = true; static int o_quiet = false; +static int run_predeliver = true; +static int run_postdeliver = true; // vdeliver is the unified e-mail message delivery agent for virtual // domains managed by vmailmgr. @@ -61,6 +63,10 @@ // Do not add the C mailbox line to the top of the message. // Note that this line is never added when the message is being // re-injected into the mail stream. (default) + { 0, "no-predeliver", cli_option::flag, false, &run_predeliver, + "Do not run vdeliver-predeliver scripts", 0 }, + { 0, "no-postdeliver", cli_option::flag, false, &run_postdeliver, + "Do not run vdeliver-postdeliver scripts", 0 }, { 0, "quiet", cli_option::flag, true, &o_quiet, "Suppress all status messages", 0 }, { 'r', 0, cli_option::flag, false, &addrpline, @@ -315,35 +321,49 @@ if(!adddtline) dtline = 0; - vpwentry* vpw = domain.lookup(ext, false); + vpwentry* vpw = domain.lookup(ext); + if(!vpw) + vpw = domain.lookup(config->default_username()); if(!vpw) die_fail(mystring("Invalid or unknown virtual user '" + ext + "'").c_str()); if(vpw->expiry < (unsigned)time(0)) die_fail(mystring("Virtual user '" + ext + "' has expired").c_str()); vpw->export_env(); - bool enabled = vpw->is_mailbox_enabled && !!vpw->mailbox; + bool do_delivery = vpw->has_mailbox && vpw->is_mailbox_enabled && + !!vpw->directory; - int r = execute("vdeliver-predeliver"); - if(r) - exit_msg("Execution of vdeliver-predeliver failed", r); + if (run_predeliver) { + int r = execute("vdeliver-predeliver"); + if(r) + if(r == 99) + return 99; + else + exit_msg("Execution of vdeliver-predeliver failed", r); + } - if(enabled) { - maildir = vpw->mailbox; + if(do_delivery) { + maildir = vpw->directory; deliver_partial(); } if(!!vpw->forwards) enqueue(vpw->forwards, host, sender); - if(enabled) + if(do_delivery) deliver_final(); if(!fin.rewind()) { if(!o_quiet) fout << "Could not re-rewind standard input" << endl; } - else if(execute("vdeliver-postdeliver")) - if(!o_quiet) - fout << "Execution of vdeliver-postdeliver failed" << endl; - + else { + if (run_postdeliver) { + int r = execute("vdeliver-postdeliver"); + if(r && r != 99) + if(!o_quiet) + fout << "Execution of vdeliver-postdeliver failed" << endl; + return r; + } + } + return 0; }