Exemplo n.º 1
0
bool sendEMailCommand (TCPSocket &sock, const std::string &command, u32 code = 250)
{
    std::string buffer = command + "\r\n";
    u32 size = (u32)buffer.size();
    if(!command.empty())
    {
        if (sock.send ((u8 *)buffer.c_str(), size) != Sock::eSockResult_Ok)
        {
            Warning("EMAIL: Can't send data to the server");
            return false;
        }
    }

    std::string res;
    char c;
    for(;;)
    {
        size = 1;
        if (sock.receive((u8*)&c, size, false) == Sock::eSockResult_Ok)
        {
            res += c;
            if (c == '\n')
            {
                u32 c;
                Email::fromString(res, c);
                if (c != code)
                {
                    Warning ("EMAIL: EMail command '%s' returned '%s' instead of code %d on sock %s", command.substr(0, 20).c_str(), res.substr(0, res.size()-2).c_str(), code, sock.remoteAddr().asString().c_str());
                    return false;
                }
                return true;
            }
        }
        else
        {
            Warning ("EMAIL: EMail connection closed before end of line, command '%s' returned '%s' on sock %s (code %d)", command.substr(0, 20).c_str(), res.c_str(), sock.remoteAddr().asString().c_str(), code);
            return false;
        }
    }

    return true;
}