Added support for RFC-3348 (Child Mailbox extension for IMAP). Renamed FLAG_CHILDREN to FLAG_HAS_CHILDREN.

This commit is contained in:
Vincent Richard 2013-12-31 11:35:29 +01:00
parent 5607c9b189
commit e13a9d19bc
8 changed files with 48 additions and 12 deletions

View File

@ -97,8 +97,8 @@ public:
*/
enum Flags
{
FLAG_CHILDREN = (1 << 0), /**< Folder contains subfolders. */
FLAG_NO_OPEN = (1 << 1), /**< Folder cannot be open. */
FLAG_HAS_CHILDREN = (1 << 0), /**< Folder contains subfolders. */
FLAG_NO_OPEN = (1 << 1), /**< Folder cannot be open. */
FLAG_UNDEFINED = 9999 /**< Used internally (this should not be returned
by the type() function). */

View File

@ -540,6 +540,20 @@ bool IMAPConnection::hasCapability(const string& capa)
}
bool IMAPConnection::hasCapability(const string& capa) const
{
const string normCapa = utility::stringUtils::toUpper(capa);
for (size_t i = 0, n = m_capabilities.size() ; i < n ; ++i)
{
if (m_capabilities[i] == normCapa)
return true;
}
return false;
}
void IMAPConnection::invalidateCapabilities()
{
m_capabilities.clear();

View File

@ -94,6 +94,7 @@ public:
void invalidateCapabilities();
const std::vector <string> getCapabilities();
bool hasCapability(const string& capa);
bool hasCapability(const string& capa) const;
shared_ptr <security::authenticator> getAuthenticator();

View File

@ -118,7 +118,7 @@ int IMAPFolder::getFlags()
// Root folder
if (m_path.isEmpty())
{
return (FLAG_CHILDREN | FLAG_NO_OPEN);
return (FLAG_HAS_CHILDREN | FLAG_NO_OPEN);
}
else
{
@ -249,7 +249,7 @@ void IMAPFolder::open(const int mode, bool failIfModeIsNotAvailable)
(responseData->mailbox_data()->mailbox_flag_list());
m_flags = IMAPUtils::folderFlagsFromFlags
(responseData->mailbox_data()->mailbox_flag_list());
(connection, responseData->mailbox_data()->mailbox_flag_list());
break;
}
@ -502,7 +502,7 @@ int IMAPFolder::testExistAndGetType()
(mailboxData->mailbox_list()->mailbox_flag_list());
m_flags = IMAPUtils::folderFlagsFromFlags
(mailboxData->mailbox_list()->mailbox_flag_list());
(m_connection, mailboxData->mailbox_list()->mailbox_flag_list());
}
}
@ -742,7 +742,7 @@ std::vector <shared_ptr <folder> > IMAPFolder::getFolders(const bool recursive)
v.push_back(make_shared <IMAPFolder>(path, store,
IMAPUtils::folderTypeFromFlags(mailbox_flag_list),
IMAPUtils::folderFlagsFromFlags(mailbox_flag_list)));
IMAPUtils::folderFlagsFromFlags(m_connection, mailbox_flag_list)));
}
}

View File

@ -1811,6 +1811,10 @@ public:
m_type = NOSELECT;
else if (name == "unmarked")
m_type = UNMARKED;
else if (name == "haschildren")
m_type = HASCHILDREN;
else if (name == "hasnochildren")
m_type = HASNOCHILDREN;
else
{
m_type = UNKNOWN;
@ -1833,6 +1837,11 @@ public:
enum Type
{
// RFC-3348 - Child Mailbox Extension
HASCHILDREN,
HASNOCHILDREN,
// Standard mailbox flags
UNKNOWN,
MARKED,
NOINFERIORS,

View File

@ -386,10 +386,16 @@ int IMAPUtils::folderTypeFromFlags(const IMAPParser::mailbox_flag_list* list)
}
int IMAPUtils::folderFlagsFromFlags(const IMAPParser::mailbox_flag_list* list)
int IMAPUtils::folderFlagsFromFlags
(shared_ptr <const IMAPConnection> cnt, const IMAPParser::mailbox_flag_list* list)
{
// Get folder flags
int folderFlags = folder::FLAG_CHILDREN;
int folderFlags = 0;
// If CHILDREN extension (RFC-3348) is not supported, assume folder has children
// as we have no hint about it
if (!cnt->hasCapability("CHILDREN"))
folderFlags |= folder::FLAG_HAS_CHILDREN;
const std::vector <IMAPParser::mailbox_flag*>& flags = list->flags();
for (std::vector <IMAPParser::mailbox_flag*>::const_iterator it = flags.begin() ;
@ -398,7 +404,11 @@ int IMAPUtils::folderFlagsFromFlags(const IMAPParser::mailbox_flag_list* list)
if ((*it)->type() == IMAPParser::mailbox_flag::NOSELECT)
folderFlags |= folder::FLAG_NO_OPEN;
else if ((*it)->type() == IMAPParser::mailbox_flag::NOINFERIORS)
folderFlags &= ~folder::FLAG_CHILDREN;
folderFlags &= ~folder::FLAG_HAS_CHILDREN;
else if ((*it)->type() == IMAPParser::mailbox_flag::HASNOCHILDREN)
folderFlags &= ~folder::FLAG_HAS_CHILDREN;
else if ((*it)->type() == IMAPParser::mailbox_flag::HASCHILDREN)
folderFlags |= folder::FLAG_HAS_CHILDREN;
}
return (folderFlags);

View File

@ -67,7 +67,9 @@ public:
static const string quoteString(const string& text);
static int folderTypeFromFlags(const IMAPParser::mailbox_flag_list* list);
static int folderFlagsFromFlags(const IMAPParser::mailbox_flag_list* list);
static int folderFlagsFromFlags
(shared_ptr <const IMAPConnection> cnt,
const IMAPParser::mailbox_flag_list* list);
static int messageFlagsFromFlags(const IMAPParser::flag_list* list);

View File

@ -105,7 +105,7 @@ int maildirFolder::getFlags()
int flags = 0;
if (m_store.lock()->getFormat()->folderHasSubfolders(m_path))
flags |= FLAG_CHILDREN; // Contains at least one sub-folder
flags |= FLAG_HAS_CHILDREN; // Contains at least one sub-folder
return (flags);
}