diff options
Diffstat (limited to 'kmail/kmfolderdir.cpp')
-rw-r--r-- | kmail/kmfolderdir.cpp | 57 |
1 files changed, 53 insertions, 4 deletions
diff --git a/kmail/kmfolderdir.cpp b/kmail/kmfolderdir.cpp index 46aba345c..1ecab637b 100644 --- a/kmail/kmfolderdir.cpp +++ b/kmail/kmfolderdir.cpp @@ -163,6 +163,31 @@ TQString KMFolderDir::prettyURL() const return label(); } +//----------------------------------------------------------------------------- +void KMFolderDir::addDirToParent( const TQString &dirName, KMFolder *parentFolder ) +{ + KMFolderDir* folderDir = new KMFolderDir( parentFolder, this, dirName, mDirType); + folderDir->reload(); + append( folderDir ); + parentFolder->setChild( folderDir ); +} + +// Get the default folder type of the given dir type. This function should only be used when +// needing to find out what the folder type of a missing folder is. +KMFolderType dirTypeToFolderType( KMFolderDirType dirType ) +{ + switch( dirType ) { + + // Use maildir for normal folder dirs, as this function is only called when finding a dir + // without a parent folder, which can only happen with maildir-like folders + case KMStandardDir: return KMFolderTypeMaildir; + + case KMImapDir: return KMFolderTypeImap; + case KMDImapDir: return KMFolderTypeCachedImap; + case KMSearchDir: return KMFolderTypeSearch; + default: Q_ASSERT( false ); return KMFolderTypeMaildir; + } +} //----------------------------------------------------------------------------- bool KMFolderDir::reload(void) @@ -272,6 +297,7 @@ bool KMFolderDir::reload(void) } } + TQStringList dirsWithoutFolder = diList; for (folder=folderList.first(); folder; folder=folderList.next()) { for(TQStringList::Iterator it = diList.begin(); @@ -279,13 +305,36 @@ bool KMFolderDir::reload(void) ++it) if (*it == "." + folder->fileName() + ".directory") { - KMFolderDir* folderDir = new KMFolderDir( folder, this, *it, mDirType); - folderDir->reload(); - append(folderDir); - folder->setChild(folderDir); + dirsWithoutFolder.remove( *it ); + addDirToParent( *it, folder ); break; } } + + // Check if the are any dirs without an associated folder. This can happen if the user messes + // with the on-disk folder structure, see kolab issue 2972. In that case, we don't want to loose + // the subfolders as well, so we recreate the folder so the folder/dir hierachy is OK again. + if ( type() == KMDImapDir ) { + for ( TQStringList::Iterator it = dirsWithoutFolder.begin(); + it != dirsWithoutFolder.end(); ++it ) { + + // .foo.directory => foo + TQString folderName = *it; + int right = folderName.find( ".directory" ); + int left = folderName.find( "." ); + Q_ASSERT( left != -1 && right != -1 ); + folderName = folderName.mid( left + 1, right - 1 ); + + kdDebug(5006) << "Found dir without associated folder: " << ( *it ) << ", recreating the folder " << folderName << "." << endl; + + // Recreate the missing folder + KMFolder *folder = new KMFolder( this, folderName, KMFolderTypeCachedImap ); + append( folder ); + folderList.append( folder ); + + addDirToParent( *it, folder ); + } + } return TRUE; } |