Read some more specs, cleaned Protocol a bit.

* Added some TODO comments based on the various IMAP specs and extensions.
* Removed SelectMailbox() functionality from the Protocol class; it's not
  really useful to have it there.
* Removed some other methods that don't belong into the Protocol class.
This commit is contained in:
Axel Dörfler 2011-12-03 01:05:11 +01:00
parent db0a4f2c00
commit 1704480100
5 changed files with 19 additions and 54 deletions

View File

@ -216,6 +216,7 @@ SelectCommand::CommandString()
return "";
BString command = "SELECT \"";
// TODO: properly quote the string!
command += fMailboxName;
command += "\"";
return command;

View File

@ -39,6 +39,7 @@ enum MessageFlags {
kFlagged = 0x04,
kDeleted = 0x08,
kDraft = 0x10
// \Recent doesn't really have any useful meaning, so we just ignore it
};

View File

@ -28,7 +28,6 @@ Protocol::Protocol()
fSocket(NULL),
fBufferedSocket(NULL),
fCommandID(0),
fStopNow(0),
fIsConnected(false)
{
}
@ -44,21 +43,6 @@ Protocol::~Protocol()
}
void
Protocol::SetStopNow()
{
atomic_set(&fStopNow, 1);
}
bool
Protocol::StopNow()
{
return (atomic_get(&fStopNow) != 0);
}
status_t
Protocol::Connect(const BNetworkAddress& address, const char* username,
const char* password, bool useSSL)
@ -93,6 +77,16 @@ Protocol::Connect(const BNetworkAddress& address, const char* username,
}
_ParseCapabilities(login.Capabilities());
if (fCapabilities.IsEmpty()) {
CapabilityHandler capabilityHandler;
status = ProcessCommand(capabilityHandler);
if (status != B_OK)
return status;
_ParseCapabilities(capabilityHandler.Capabilities());
}
return B_OK;
}
@ -179,29 +173,6 @@ Protocol::UnsubscribeFolder(const char* folder)
}
status_t
Protocol::SelectMailbox(const char* mailbox)
{
TRACE("SELECT %s\n", mailbox);
SelectCommand command(mailbox);
status_t status = ProcessCommand(command);
if (status != B_OK)
return status;
if (fCapabilities.IsEmpty()) {
CapabilityHandler capabilityHandler;
status = ProcessCommand(capabilityHandler);
if (status != B_OK)
return status;
_ParseCapabilities(capabilityHandler.Capabilities());
}
fMailbox = mailbox;
return B_OK;
}
status_t
Protocol::GetQuota(uint64& used, uint64& total)
{

View File

@ -55,11 +55,6 @@ public:
Protocol();
~Protocol();
/*! Indicates that the current action should be interrupted because
we are going to be deleted. */
void SetStopNow();
bool StopNow();
status_t Connect(const BNetworkAddress& address,
const char* username, const char* password,
bool useSSL = true);
@ -70,17 +65,12 @@ public:
status_t SendCommand(int32 id, const char* command);
ssize_t SendData(const char* buffer, uint32 length);
// Some convenience methods
status_t GetFolders(FolderList& folders);
status_t SubscribeFolder(const char* folder);
status_t UnsubscribeFolder(const char* folder);
status_t SelectMailbox(const char* mailbox);
const BString& Mailbox() const { return fMailbox; }
status_t GetQuota(uint64& used, uint64& total);
/*! Install a temporary handler at first position in the handler
list. */
status_t ProcessCommand(Command& command,
bigtime_t timeout = kIMAP4ClientTimeout);
@ -117,12 +107,10 @@ protected:
ArgumentList fCapabilities;
private:
BString fMailbox;
int32 fCommandID;
CommandIDMap fOngoingCommands;
BString fCommandError;
vint32 fStopNow;
bool fIsConnected;
};

View File

@ -53,8 +53,12 @@ do_select(int argc, char** argv)
if (argc > 1)
folder = argv[1];
status_t status = sProtocol.SelectMailbox(folder);
if (status != B_OK)
IMAP::SelectCommand command(folder);
status_t status = sProtocol.ProcessCommand(command);
if (status == B_OK) {
printf("Next UID: %" B_PRIu32 ", UID validity: %" B_PRIu32 "\n",
command.NextUID(), command.UIDValidity());
} else
error("select", status);
}