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