Completed literal handling.

* LiteralHandler commands now receive the literal data as intended.
* The 'fetch' command in the imap_tester now uses this to print the literal
  to stdout.
This commit is contained in:
Axel Dörfler
2015-01-06 15:21:03 +01:00
parent 3e4e5c2cf6
commit 077338a9b8
3 changed files with 41 additions and 5 deletions
@@ -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. * Copyright 2010 Clemens Zeidler. All rights reserved.
* *
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
@@ -243,10 +243,15 @@ Protocol::ProcessCommand(Command& command, bigtime_t timeout)
status_t status_t
Protocol::HandleResponse(bigtime_t timeout, bool disconnectOnTimeout) Protocol::HandleResponse(Command* command, bigtime_t timeout,
bool disconnectOnTimeout)
{ {
status_t commandStatus = B_OK; status_t commandStatus = B_OK;
IMAP::ResponseParser parser(*fBufferedSocket); IMAP::ResponseParser parser(*fBufferedSocket);
if (IMAP::LiteralHandler* literalHandler
= dynamic_cast<IMAP::LiteralHandler*>(command))
parser.SetLiteralHandler(literalHandler);
IMAP::Response response; IMAP::Response response;
bool done = false; bool done = false;
@@ -329,7 +334,7 @@ Protocol::_ProcessCommandWithoutAfterQuake(Command& command, bigtime_t timeout)
status_t status = SendCommand(commandID, commandString.String()); status_t status = SendCommand(commandID, commandString.String());
if (status == B_OK) { if (status == B_OK) {
fOngoingCommands[commandID] = &command; fOngoingCommands[commandID] = &command;
status = HandleResponse(timeout); status = HandleResponse(&command, timeout);
} }
if (handler != NULL) if (handler != NULL)
@@ -82,7 +82,7 @@ public:
const BString& CommandError() { return fCommandError; } const BString& CommandError() { return fCommandError; }
protected: protected:
status_t HandleResponse( status_t HandleResponse(Command* command,
bigtime_t timeout = kIMAP4ClientTimeout, bigtime_t timeout = kIMAP4ClientTimeout,
bool disconnectOnTimeout = true); bool disconnectOnTimeout = true);
void ProcessAfterQuacks(bigtime_t timeout); void ProcessAfterQuacks(bigtime_t timeout);
+32 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2011, Axel Dörfler, [email protected]. * Copyright 2011-2012, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@@ -107,6 +107,37 @@ do_fetch(int argc, char** argv)
from = to = atoul(argv[1]); from = to = atoul(argv[1]);
IMAP::FetchCommand command(from, to, mode); 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); status_t status = sProtocol.ProcessCommand(command);
if (status != B_OK) { if (status != B_OK) {
error("fetch", status); error("fetch", status);