#include <iostream>
#include <fstream>
#include <string>
#include <ctime>

/* !!Remember!! chances are the caller of sendmail is jailed (chroot'd)
in some directory (like /var/www on *nix systems, or C:\www on Windows),
so the log file will be relative to that path (even if it's absolute). */

#if defined(_MSC_VER)
    // windows write to same location as exe file
    #define FAKE_LOG_FILE "sendmail.log"
#else
    #define FAKE_LOG_FILE "/logs/sendmail.log"
#endif

int main(int argc, char* argv[])
{
    std::time_t result = std::time(NULL);
    std::ofstream file;
    file.open(FAKE_LOG_FILE, std::fstream::app);
    file << "FAKE MAIL CALLED: " << std::ctime(&result);
    file << "ARGUMENTS: ";
    for (int i = 0; i < argc; ++i) {
        file << argv[i] << " ";
    }
    file << std::endl << "---START EMAIL---" << std::endl;
    for (std::string line; std::getline(std::cin, line);) {
        file << line << std::endl;
    }
    file << "----END EMAIL----" << std::endl << std::endl;
    file.close();
    return 0;
}
