#ifndef __POP3Session_h__ #define __POP3Session_h__ #include "TCPServer.h" #include "TCPSession.h" #include "MailFolder.h" #include #define CRLF "\r\n" namespace mail { class POP3Session : public core::TCPSession { public: POP3Session(core::EPoll &ePoll, core::TCPServer &server) : TCPSession(ePoll, &server, "POP3 Client Session") {} std::string clientDomainName; // RFC 1939 4/7: USER sets the pending username and replies +OK // without checking anything - only PASS actually authenticates // (against MailFileSystem::checkPassword(), shared with SMTP AUTH // and IMAP LOGIN). userName is meaningless until PASS succeeds; // authenticated gates every other command per RFC 1939 3's state // diagram (AUTHORIZATION vs TRANSACTION state). std::string userName; bool authenticated = false; // Loaded once, right after a successful PASS - POP3 has no // folder concept (RFC 1939 has no SELECT-equivalent), it only // ever operates on Inbox. RFC 1939 3's "maildrop" message // numbering is fixed for the whole session (assigned once here, // not re-derived per command) even if new mail is delivered // mid-session - deletedMarks/QUIT below follow the same // session-frozen-snapshot model. MailFolder mailbox; // RFC 1939 3: DELE only MARKS a message deleted - the mark (and // any RSET undoing it) is session-local and has no effect until // QUIT actually commits it by unlinking the marked messages. // Keyed by 1-based POP3 message number (this session's frozen // ordering), not UID. std::set deletedMarks; // RFC 1939 4: the server must send a positive greeting before the // client sends anything. void onConnected() override { out << "+OK POP3 server ready" << CRLF; } }; } #endif