#include "__POP3_PASS.h" #include "POP3Server.h" namespace mail { int __POP3_PASS::processCommand(coreutils::ZString request, POP3Session &session, POP3Server &server) { request.skipWhitespace(); // Deliberately the rest of the line, not just the first // whitespace-delimited token - RFC 1939 4's PASS may // contain any character except CR/LF, spaces included. (A known, // documented gap of this same shape exists nowhere else in this // codebase for POP3, since every other POP3 argument is a bare // number or single atom that's never expected to contain a // space.) coreutils::ZString passArg = request.unparsed(); if (session.userName.empty()) { session.out << "-ERR USER required first" << CRLF; return 1; } if (passArg.getLength() == 0) { session.out << "-ERR Usage: PASS " << CRLF; return 1; } coreutils::ZString userNameZ(session.userName); if (!server.mailFileSystem.checkPassword(userNameZ, passArg)) { session.out << "-ERR Authentication failed" << CRLF; session.userName.clear(); return 1; } coreutils::ZString userNameZ2(session.userName); std::string mailboxPath = server.mailFileSystem.getFolderPath(userNameZ2, "Inbox").str(); session.mailbox.load(mailboxPath); session.authenticated = true; session.out << "+OK Logged in" << CRLF; return 1; } }