IMAP: Use BStringList instead of STL vector.

This commit is contained in:
Axel Dörfler
2015-12-22 19:35:09 +01:00
parent e69a3a86fc
commit 29871039d7
5 changed files with 39 additions and 39 deletions
@@ -41,7 +41,7 @@ IMAPProtocol::CheckSubscribedFolders(IMAP::Protocol& protocol, bool idle)
{
// Get list of subscribed folders
StringList newFolders;
BStringList newFolders;
BString separator;
status_t status = protocol.GetSubscribedFolders(newFolders, separator);
if (status != B_OK)
@@ -49,20 +49,19 @@ IMAPProtocol::CheckSubscribedFolders(IMAP::Protocol& protocol, bool idle)
// Determine how many new mailboxes we have
StringList::iterator folderIterator = newFolders.begin();
while (folderIterator != newFolders.end()) {
if (fFolders.find(*folderIterator) != fFolders.end())
folderIterator = newFolders.erase(folderIterator);
for (int32 i = 0; i < newFolders.CountStrings();) {
if (fFolders.find(newFolders.StringAt(i)) != fFolders.end())
newFolders.Remove(i);
else
folderIterator++;
i++;
}
int32 totalMailboxes = fFolders.size() + newFolders.size();
int32 totalMailboxes = fFolders.size() + newFolders.CountStrings();
int32 workersWanted = 1;
if (idle)
workersWanted = std::min(fSettings.MaxConnections(), totalMailboxes);
if (newFolders.empty() && fWorkers.CountItems() == workersWanted) {
if (newFolders.IsEmpty() && fWorkers.CountItems() == workersWanted) {
// Nothing to do - we've already distributed everything
return B_OK;
}
@@ -95,9 +94,8 @@ IMAPProtocol::CheckSubscribedFolders(IMAP::Protocol& protocol, bool idle)
}
// Update known mailboxes
folderIterator = newFolders.begin();
for (; folderIterator != newFolders.end(); folderIterator++) {
const BString& mailbox = *folderIterator;
for (int32 i = 0; i < newFolders.CountStrings(); i++) {
const BString& mailbox = newFolders.StringAt(i);
fFolders.insert(std::make_pair(mailbox,
_CreateFolder(mailbox, separator)));
}
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2013, Haiku, Inc. All rights reserved.
* Copyright 2011-2015, Haiku, Inc. All rights reserved.
* Copyright 2011, Clemens Zeidler <[email protected]>
* Distributed under the terms of the MIT License.
*/
@@ -696,12 +696,12 @@ ListCommand::HandleUntagged(Response& response)
// The folder INBOX is always case insensitive
if (folder.ICompare("INBOX") == 0)
folder = "Inbox";
fFolders.push_back(folder);
fFolders.Add(folder);
} catch (ParseException& exception) {
// Decoding failed, just add the plain text
fprintf(stderr, "Decoding \"%s\" failed: %s\n", folder.String(),
exception.Message());
fFolders.push_back(folder);
fFolders.Add(folder);
}
return true;
}
@@ -710,7 +710,7 @@ ListCommand::HandleUntagged(Response& response)
}
const StringList&
const BStringList&
ListCommand::FolderList()
{
return fFolders;
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2013, Haiku Inc. All Rights Reserved.
* Copyright 2010-2015, Haiku Inc. All Rights Reserved.
* Copyright 2010 Clemens Zeidler. All rights reserved.
*
* Distributed under the terms of the MIT License.
@@ -8,14 +8,13 @@
#define COMMANDS_H
#include <StringList.h>
#include <vector>
#include "Response.h"
typedef std::vector<BString> StringList;
namespace IMAP {
@@ -284,7 +283,7 @@ public:
virtual BString CommandString();
virtual bool HandleUntagged(Response& response);
const StringList& FolderList();
const BStringList& FolderList();
const BString& Separator() { return fSeparator; }
private:
@@ -293,7 +292,7 @@ private:
private:
RFC3501Encoding fEncoding;
const char* fPrefix;
StringList fFolders;
BStringList fFolders;
BString fSeparator;
bool fSubscribedOnly;
};
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2013, Haiku Inc. All Rights Reserved.
* Copyright 2010-2015, Haiku Inc. All Rights Reserved.
* Copyright 2010 Clemens Zeidler. All rights reserved.
*
* Distributed under the terms of the MIT License.
@@ -152,22 +152,22 @@ Protocol::RemoveHandler(Handler& handler)
status_t
Protocol::GetFolders(FolderList& folders, BString& separator)
{
StringList allFolders;
BStringList allFolders;
status_t status = _GetAllFolders(allFolders);
if (status != B_OK)
return status;
StringList subscribedFolders;
BStringList subscribedFolders;
status = GetSubscribedFolders(subscribedFolders, separator);
if (status != B_OK)
return status;
for (size_t i = 0; i < allFolders.size(); i++) {
for (int32 i = 0; i < allFolders.CountStrings(); i++) {
FolderEntry entry;
entry.folder = allFolders[i];
for (unsigned int a = 0; a < subscribedFolders.size(); a++) {
if (allFolders[i] == subscribedFolders[a]
|| allFolders[i].ICompare("INBOX") == 0) {
entry.folder = allFolders.StringAt(i);
for (int32 j = 0; j < subscribedFolders.CountStrings(); j++) {
if (entry.folder == subscribedFolders.StringAt(j)
|| entry.folder.ICompare("INBOX") == 0) {
entry.subscribed = true;
break;
}
@@ -176,10 +176,10 @@ Protocol::GetFolders(FolderList& folders, BString& separator)
}
// you could be subscribed to a folder which not exist currently, add them:
for (size_t a = 0; a < subscribedFolders.size(); a++) {
for (int32 i = 0; i < subscribedFolders.CountStrings(); i++) {
bool isInlist = false;
for (size_t i = 0; i < allFolders.size(); i++) {
if (subscribedFolders[a] == allFolders[i]) {
for (int32 j = 0; j < allFolders.CountStrings(); j++) {
if (subscribedFolders.StringAt(i) == allFolders.StringAt(j)) {
isInlist = true;
break;
}
@@ -188,7 +188,7 @@ Protocol::GetFolders(FolderList& folders, BString& separator)
continue;
FolderEntry entry;
entry.folder = subscribedFolders[a];
entry.folder = subscribedFolders.StringAt(i);
entry.subscribed = true;
folders.push_back(entry);
}
@@ -198,7 +198,7 @@ Protocol::GetFolders(FolderList& folders, BString& separator)
status_t
Protocol::GetSubscribedFolders(StringList& folders, BString& separator)
Protocol::GetSubscribedFolders(BStringList& folders, BString& separator)
{
ListCommand command(NULL, true);
status_t status = ProcessCommand(command);
@@ -391,7 +391,7 @@ Protocol::_Disconnect()
status_t
Protocol::_GetAllFolders(StringList& folders)
Protocol::_GetAllFolders(BStringList& folders)
{
ListCommand command(NULL, false);
status_t status = ProcessCommand(command);
@@ -1,5 +1,5 @@
/*
* Copyright 2001-2013, Haiku Inc. All Rights Reserved.
* Copyright 2001-2015, Haiku Inc. All Rights Reserved.
* Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
* Copyright 2010 Clemens Zeidler. All rights reserved.
*
@@ -21,7 +21,10 @@
#define xEOF 236
const bigtime_t kIMAP4ClientTimeout = 1000000 * 60; // 60 sec
const bigtime_t kIMAP4ClientTimeout = 1000000 * 60;
// 60 seconds
namespace IMAP {
@@ -66,7 +69,7 @@ public:
// Some convenience methods
status_t GetFolders(FolderList& folders,
BString& separator);
status_t GetSubscribedFolders(StringList& folders,
status_t GetSubscribedFolders(BStringList& folders,
BString& separator);
status_t SubscribeFolder(const char* folder);
status_t UnsubscribeFolder(const char* folder);
@@ -92,7 +95,7 @@ protected:
private:
status_t _Disconnect();
status_t _GetAllFolders(StringList& folders);
status_t _GetAllFolders(BStringList& folders);
void _ParseCapabilities(
const ArgumentList& arguments);