#include "handler.ih"

void Handler::getTheZip()
{
    if (not g_options.specs().empty())          // explicitly specify a
    {                                           // zip using the -s option
                                                // (no name check with -s)
        string zipname = basename(d_zip);       
        d_exec.execute("/bin/cp " + d_zip + ' ' + zipname);
        d_zip = zipname;
    }
    else                                        // or retrieve the zip
    {                                           // from the mail's attachment
        if (g_options.gpg())
            saveSignature("signature");

        nextBoundary();     // find the next section, containing the zip

        saveZipFile();      // save the zip file

        if 
        (
            g_options.gpg() 
            and 
            not d_exec.execute("/usr/bin/gpg --verify signature " + d_zip)
        )
        {
            if (d_exec.ret() != 2)
                throw Exception{REPLY} << 
                            "`/usr/bin/gpg --verify: " << d_zip <<
                            "': BAD signature";

            throw Exception{REPLY} <<
                            "`/usr/bin/gpg --verify: " << d_zip <<
                    "Buggy signature: maybe the signature contained quoted "
                                                    "printable characters\n"
                    "Check Your mail-text headers. It should use\n"
                    "   Encoding: 7bit\n"
                    "and not:\n"
                    "   Encoding: quoted-printable";
        }
    }
}
