#define XERR
#include "handler.ih"

void Handler::run()
{
    headers();              // get From:, Date: and the boundary (or use -s)

    verifyAddress();        // From: must hold a known mailing-list address

    if (d_publicKey)
    {
        publicKey();

        mail(PUBLIC_KEY);
        return;
    }

    workingDir();           // create and chdir to the working dir.

    getTheZip();    

    if (not d_exec.execute("/usr/bin/unzip " + d_zip))
        throw Exception{REPLY} << "Cannot unzip " << d_zip;

    if (not d_zipCheck.inspect(d_zip))
    {
        log() << "rejected: zip file contains invalid files\n";
        throw Exception{REPLY} << "Zip file content error(s):\n" <<
                                      d_zipCheck.error();
    }

    inspectMetadata();       // check the content of metadata.txt

    setCCs();               // set the CC addresses

    compile();              // compile all top- and next level .cc/.cpp files.

    makePdf();

    rotate();               // rotate raters on 1st submissions

    storeSpoolPath();       // store the info in the spoolpath

    g_options.allOK();      // at this point all's OK

    mail(d_pdf2from ? PDF : EXERCISES);     // send confirmatory e-mail
                                            // or the zip+pdf to d_from

    mailZip();              // send zips to addresses listed in mailZip()
}




