IMAP (RFC 3501): LOGIN through UID, previously all stubs except CAPABILITY/LOGOUT/a partial APPEND. Multi-folder support with per-folder UID/flag indexing (new MailFolder class, backed by .uidvalidity/.uidnext/ .imapindex sidecar files), ENVELOPE support (new MessageHeaders class: header parsing, address-list parsing, IMAP quoting), and shared cursor-based argument parsing (new IMAPArgs class: sequence sets, flag lists, dates, folder-name normalization, and path-traversal protection via isValidFolderName - a bare ".." folder name would otherwise resolve into a sibling user's mailbox directory). POP3 (RFC 1939): USER through QUIT, previously only CAPA. Added UIDL. POP3 handlers use cursor-based parsing throughout rather than indexed access - ZString's copy constructor doesn't copy its `list` field, and POP3's dispatch passes the request by value, so indexed access into a copy was silently reading nothing. SMTP: DMARC evaluation added to the DATA-terminator path (DKIM verification + alignment/policy, Authentication-Results header, conditional rejection matching RFC 7489 6.3's p=reject + sampled pct=). AUTH LOGIN now handles RFC 4954's optional inline initial response (e.g. Python smtplib's "AUTH LOGIN <base64>" in one line) instead of only the exact three-line form. Outbound relay now forces IPv4 (AF_INET) instead of AF_UNSPEC - this server's IPv4 has a correct PTR record and SPF coverage, its IPv6 doesn't, and Gmail was rejecting outbound mail with 550 5.7.25 as a result. Delivery pipeline: local delivery now runs the message through SpamAssassin (new SpamAssassinFilter class, speaking spamd's PROCESS protocol directly over a raw socket - fails open/delivers unscanned if spamd is unreachable) instead of a plain hardlink, since scanning can tag/modify content. BARANTMailConfig: extracted config loading into its own class. compile: (see individual file changes - build script adjustments to match the above). Deliberately excluded from this commit: barantmail.log/ barantmail-service.log (operational logs, not source - barantmail.log in particular was the runaway 55GB/12.9GB file from a busy-loop bug fixed separately in ServerCore) and barantmail.cfg (this server's own live deployment config, matching how APIServer's equivalent config also stays untracked).
45 lines
2.4 KiB
C++
45 lines
2.4 KiB
C++
# include "Command.h"
|
|
# include "IMAPSession.h"
|
|
# include "IMAPServer.h"
|
|
# include "Log.h"
|
|
|
|
namespace mail {
|
|
|
|
int IMAPCommand::processCommand(coreutils::ZString &request, core::TCPSession &session) {
|
|
// session.server is a TCPServer* (pointer) - C-style-casting the
|
|
// POINTER VALUE directly to a reference type does not dereference
|
|
// it. Per C++'s reference-cast rules this falls back to
|
|
// reinterpret_cast<T&>, which for an expression that is not
|
|
// itself an object is *reinterpret_cast<T*>(&expr) - i.e. it took
|
|
// the address of the `session.server` POINTER FIELD ITSELF (8
|
|
// bytes, wherever that field happens to live inside the
|
|
// TCPSession/IMAPSession object) and read an entire IMAPServer's
|
|
// worth of memory starting there, not the real IMAPServer object
|
|
// the pointer actually points to. Confirmed live via gdb: fields
|
|
// read off the "IMAPServer" this produced were complete garbage
|
|
// (a null EPoll reference, a socket descriptor of -136794095).
|
|
// The compiler's own "does not dereference pointer" warning on
|
|
// this exact line, present on every build all session, was
|
|
// reporting precisely this. Dereferencing the pointer first
|
|
// (*session.server, a real TCPServer&) makes the cast to
|
|
// IMAPServer& a normal, correct base-to-derived downcast.
|
|
// CommandList::processRequest() (ServerCore) calls request.reset()
|
|
// right before dispatch - the cursor lands at the true start of
|
|
// the whole command line, which STILL includes the command word
|
|
// itself ("LOGIN", "FETCH", ...), not just past it. SMTP handlers
|
|
// never noticed because they read arguments via request[N] (the
|
|
// pre-split list, built independently of cursor position) rather
|
|
// than the cursor - every IMAP handler here parses off the raw
|
|
// cursor instead (see IMAPArgs.h's own doc comment for why), so
|
|
// without this, every handler's first nextArgument() call was
|
|
// reading the command word itself as if it were the first real
|
|
// argument (confirmed live: LOGIN "user" "pass" produced
|
|
// userArg=="LOGIN", passArg=="user", with "pass" never read at
|
|
// all). Discarding it here, once, centrally, is simpler and less
|
|
// error-prone than every individual handler remembering to do it.
|
|
request.getTokenExclude(" ");
|
|
return processCommand(request, (IMAPSession &)session, (IMAPServer &)(*session.server));
|
|
}
|
|
|
|
}
|