diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Protocol.cpp b/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Protocol.cpp index 585172f627..d27a3c6ccf 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Protocol.cpp +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Protocol.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2010-2011, Haiku Inc. All Rights Reserved. + * Copyright 2010-2012, Haiku Inc. All Rights Reserved. * Copyright 2010 Clemens Zeidler. All rights reserved. * * Distributed under the terms of the MIT License. @@ -243,10 +243,15 @@ Protocol::ProcessCommand(Command& command, bigtime_t timeout) status_t -Protocol::HandleResponse(bigtime_t timeout, bool disconnectOnTimeout) +Protocol::HandleResponse(Command* command, bigtime_t timeout, + bool disconnectOnTimeout) { status_t commandStatus = B_OK; IMAP::ResponseParser parser(*fBufferedSocket); + if (IMAP::LiteralHandler* literalHandler + = dynamic_cast(command)) + parser.SetLiteralHandler(literalHandler); + IMAP::Response response; bool done = false; @@ -329,7 +334,7 @@ Protocol::_ProcessCommandWithoutAfterQuake(Command& command, bigtime_t timeout) status_t status = SendCommand(commandID, commandString.String()); if (status == B_OK) { fOngoingCommands[commandID] = &command; - status = HandleResponse(timeout); + status = HandleResponse(&command, timeout); } if (handler != NULL) diff --git a/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Protocol.h b/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Protocol.h index 0df14b1881..7c8dd5541b 100644 --- a/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Protocol.h +++ b/src/add-ons/mail_daemon/inbound_protocols/imap/imap_lib/Protocol.h @@ -82,7 +82,7 @@ public: const BString& CommandError() { return fCommandError; } protected: - status_t HandleResponse( + status_t HandleResponse(Command* command, bigtime_t timeout = kIMAP4ClientTimeout, bool disconnectOnTimeout = true); void ProcessAfterQuacks(bigtime_t timeout); diff --git a/src/tests/add-ons/mail/imap/imap_tester.cpp b/src/tests/add-ons/mail/imap/imap_tester.cpp index b9173de98b..78414a4241 100644 --- a/src/tests/add-ons/mail/imap/imap_tester.cpp +++ b/src/tests/add-ons/mail/imap/imap_tester.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2011-2012, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. */ @@ -107,6 +107,37 @@ do_fetch(int argc, char** argv) from = to = atoul(argv[1]); IMAP::FetchCommand command(from, to, mode); + + // A fetch listener that dumps everything to stdout + class Listener : public IMAP::FetchListener { + public: + virtual bool FetchData(IMAP::Response& reponse, uint32 uid, + IMAP::FetchMode mode, BDataIO& stream, size_t length) + { + BMallocIO copy; + char buffer[65535]; + while (length > 0) { + ssize_t bytesRead = stream.Read(buffer, + min_c(sizeof(buffer), length)); + if (bytesRead <= 0) + break; + + copy.Write(buffer, bytesRead); + length -= bytesRead; + } + + // Null terminate the buffer + char null = '\0'; + copy.Write(&null, 1); + + printf("================= UID %ld =================\n", uid); + puts((const char*)copy.Buffer()); + return true; + } + } listener; + + command.SetListener(&listener); + status_t status = sProtocol.ProcessCommand(command); if (status != B_OK) { error("fetch", status);