kmail

kmfolder.cpp

00001 /* -*- mode: C++; c-file-style: "gnu" -*-
00002  * kmail: KDE mail client
00003  * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  */
00020 #include <config.h>
00021 
00022 #include "kmfolder.h"
00023 #include "kmfolderdir.h"
00024 #include "kmfoldermbox.h"
00025 #include "folderstorage.h"
00026 #include "kmfoldercachedimap.h"
00027 #include "kmfoldersearch.h"
00028 #include "kmfolderimap.h"
00029 #include "kmfoldermgr.h"
00030 #include <libkpimidentities/identitymanager.h>
00031 #include <libkpimidentities/identity.h>
00032 #include "expirejob.h"
00033 #include "compactionjob.h"
00034 #include "kmfoldertree.h"
00035 #include "kmailicalifaceimpl.h"
00036 
00037 #include <errno.h>
00038 
00039 #include <kdebug.h>
00040 #include <klocale.h>
00041 #include <kshortcut.h>
00042 #include <kmessagebox.h>
00043 #include <qfile.h>
00044 #include <qfileinfo.h>
00045 
00046 
00047 KMFolder::KMFolder( KMFolderDir* aParent, const QString& aFolderName,
00048                              KMFolderType aFolderType, bool withIndex, bool exportedSernums )
00049   : KMFolderNode( aParent, aFolderName ), mStorage(0),
00050     mChild( 0 ),
00051     mIsSystemFolder( false ),
00052     mHasIndex( withIndex ),
00053     mExportsSernums( exportedSernums ),
00054     mExpireMessages( false ), mUnreadExpireAge( 28 ),
00055     mReadExpireAge( 14 ), mUnreadExpireUnits( expireNever ),
00056     mReadExpireUnits( expireNever ),
00057     mExpireAction( ExpireDelete ),
00058     mUseCustomIcons( false ), mMailingListEnabled( false ),
00059     mAcctList( 0 ),
00060     mIdentity( 0 ), // default identity
00061     mPutRepliesInSameFolder( false ),
00062     mIgnoreNewMail( false )
00063 {
00064   if( aFolderType == KMFolderTypeCachedImap )
00065     mStorage = new KMFolderCachedImap( this, aFolderName.latin1() );
00066   else if( aFolderType == KMFolderTypeImap )
00067     mStorage = new KMFolderImap( this, aFolderName.latin1() );
00068   else if( aFolderType == KMFolderTypeMaildir )
00069     mStorage = new KMFolderMaildir( this, aFolderName.latin1() );
00070   else if( aFolderType == KMFolderTypeSearch )
00071     mStorage = new KMFolderSearch( this, aFolderName.latin1() );
00072   else
00073     mStorage = new KMFolderMbox( this, aFolderName.latin1() );
00074 
00075   assert( mStorage );
00076 
00077   QFileInfo dirinfo;
00078   dirinfo.setFile( mStorage->location() );
00079   if ( !dirinfo.exists() ) {
00080     int rc = mStorage->create();
00081     QString msg = i18n("<qt>Error while creating file <b>%1</b>:<br>%2</qt>").arg(aFolderName).arg(strerror(rc));
00082     if ( rc ) {
00083       KMessageBox::information(0, msg);
00084     }
00085   }
00086 
00087    // trigger from here, since it needs a fully constructed FolderStorage
00088   if ( mExportsSernums )
00089     mStorage->registerWithMessageDict();
00090   if ( !mHasIndex )
00091     mStorage->setAutoCreateIndex( false );
00092 
00093   if ( aParent ) {
00094     connect( mStorage, SIGNAL( msgAdded( KMFolder*, Q_UINT32 ) ),
00095              aParent->manager(), SIGNAL( msgAdded( KMFolder*, Q_UINT32 ) ) );
00096     connect( mStorage, SIGNAL( msgRemoved( KMFolder*, Q_UINT32 ) ),
00097              parent()->manager(), SIGNAL( msgRemoved( KMFolder*, Q_UINT32 ) ) );
00098     connect( this, SIGNAL( msgChanged( KMFolder*, Q_UINT32, int ) ),
00099              parent()->manager(), SIGNAL( msgChanged( KMFolder*, Q_UINT32, int ) ) );
00100     connect( this, SIGNAL( msgHeaderChanged( KMFolder*,  int ) ),
00101              parent()->manager(), SIGNAL( msgHeaderChanged( KMFolder*, int ) ) );
00102     connect( mStorage, SIGNAL( invalidated( KMFolder* ) ),
00103              parent()->manager(), SIGNAL( folderInvalidated( KMFolder* ) ) );
00104   }
00105 
00106   // Resend all mStorage signals
00107   connect( mStorage, SIGNAL( changed() ), SIGNAL( changed() ) );
00108   connect( mStorage, SIGNAL( cleared() ), SIGNAL( cleared() ) );
00109   connect( mStorage, SIGNAL( expunged( KMFolder* ) ),
00110            SIGNAL( expunged( KMFolder* ) ) );
00111   connect( mStorage, SIGNAL( nameChanged() ), SIGNAL( nameChanged() ) );
00112   connect( mStorage, SIGNAL( msgRemoved( KMFolder*, Q_UINT32 ) ),
00113            SIGNAL( msgRemoved( KMFolder*, Q_UINT32 ) ) );
00114   connect( mStorage, SIGNAL( msgRemoved( int, QString ) ),
00115            SIGNAL( msgRemoved( int, QString ) ) );
00116   connect( mStorage, SIGNAL( msgRemoved( KMFolder* ) ),
00117            SIGNAL( msgRemoved( KMFolder* ) ) );
00118   connect( mStorage, SIGNAL( msgAdded( int ) ), SIGNAL( msgAdded( int ) ) );
00119   connect( mStorage, SIGNAL( msgAdded( KMFolder*, Q_UINT32 ) ),
00120            SIGNAL( msgAdded( KMFolder*, Q_UINT32 ) ) );
00121   connect( mStorage, SIGNAL( msgChanged( KMFolder*, Q_UINT32 , int ) ),
00122            SIGNAL( msgChanged( KMFolder*, Q_UINT32 , int ) ) );
00123   connect( mStorage, SIGNAL( msgHeaderChanged( KMFolder*, int ) ),
00124            SIGNAL( msgHeaderChanged( KMFolder*, int ) ) );
00125   connect( mStorage, SIGNAL( statusMsg( const QString& ) ),
00126            SIGNAL( statusMsg( const QString& ) ) );
00127   connect( mStorage, SIGNAL( numUnreadMsgsChanged( KMFolder* ) ),
00128            SIGNAL( numUnreadMsgsChanged( KMFolder* ) ) );
00129   connect( mStorage, SIGNAL( removed( KMFolder*, bool ) ),
00130            SIGNAL( removed( KMFolder*, bool ) ) );
00131 
00132   connect( mStorage, SIGNAL( contentsTypeChanged( KMail::FolderContentsType ) ),
00133                 this, SLOT( slotContentsTypeChanged( KMail::FolderContentsType ) ) );
00134 
00135   //FIXME: Centralize all the readConfig calls somehow - Zack
00136   mStorage->readConfig();
00137 
00138   if ( mId == 0 && aParent )
00139     mId = aParent->manager()->createId();
00140 }
00141 
00142 KMFolder::~KMFolder()
00143 {
00144   delete mAcctList;
00145   if ( mHasIndex ) mStorage->deregisterFromMessageDict();
00146   delete mStorage;
00147 }
00148 
00149 void KMFolder::readConfig( KConfig* config )
00150 {
00151   if ( !config->readEntry("SystemLabel").isEmpty() )
00152     mSystemLabel = config->readEntry("SystemLabel");
00153   mExpireMessages = config->readBoolEntry("ExpireMessages", false);
00154   mReadExpireAge = config->readNumEntry("ReadExpireAge", 3);
00155   mReadExpireUnits = (ExpireUnits)config->readNumEntry("ReadExpireUnits", expireMonths);
00156   mUnreadExpireAge = config->readNumEntry("UnreadExpireAge", 12);
00157   mUnreadExpireUnits = (ExpireUnits)config->readNumEntry("UnreadExpireUnits", expireNever);
00158   mExpireAction = config->readEntry("ExpireAction", "Delete") == "Move" ? ExpireMove : ExpireDelete;
00159   mExpireToFolderId = config->readEntry("ExpireToFolder");
00160 
00161   mUseCustomIcons = config->readBoolEntry("UseCustomIcons", false );
00162   mNormalIconPath = config->readEntry("NormalIconPath" );
00163   mUnreadIconPath = config->readEntry("UnreadIconPath" );
00164 
00165   mMailingListEnabled = config->readBoolEntry("MailingListEnabled");
00166   mMailingList.readConfig( config );
00167 
00168   mIdentity = config->readUnsignedNumEntry("Identity",0);
00169 
00170   setUserWhoField( config->readEntry("WhoField"), false );
00171   uint savedId = config->readUnsignedNumEntry("Id", 0);
00172   // make sure that we don't overwrite a valid id
00173   if ( savedId != 0 && mId == 0 )
00174     mId = savedId;
00175   mPutRepliesInSameFolder = config->readBoolEntry( "PutRepliesInSameFolder", false );
00176   mIgnoreNewMail = config->readBoolEntry( "IgnoreNewMail", false );
00177 
00178   if ( mUseCustomIcons )
00179     emit iconsChanged();
00180 
00181   QString shortcut( config->readEntry( "Shortcut" ) );
00182   if ( !shortcut.isEmpty() ) {
00183     KShortcut sc( shortcut );
00184     setShortcut( sc );
00185   }
00186 }
00187 
00188 void KMFolder::writeConfig( KConfig* config ) const
00189 {
00190   config->writeEntry("SystemLabel", mSystemLabel);
00191   config->writeEntry("ExpireMessages", mExpireMessages);
00192   config->writeEntry("ReadExpireAge", mReadExpireAge);
00193   config->writeEntry("ReadExpireUnits", mReadExpireUnits);
00194   config->writeEntry("UnreadExpireAge", mUnreadExpireAge);
00195   config->writeEntry("UnreadExpireUnits", mUnreadExpireUnits);
00196   config->writeEntry("ExpireAction", mExpireAction == ExpireDelete ? "Delete" : "Move");
00197   config->writeEntry("ExpireToFolder", mExpireToFolderId);
00198 
00199   config->writeEntry("UseCustomIcons", mUseCustomIcons);
00200   config->writeEntry("NormalIconPath", mNormalIconPath);
00201   config->writeEntry("UnreadIconPath", mUnreadIconPath);
00202 
00203   config->writeEntry("MailingListEnabled", mMailingListEnabled);
00204   mMailingList.writeConfig( config );
00205 
00206   config->writeEntry("Identity", mIdentity);
00207 
00208   config->writeEntry("WhoField", mUserWhoField);
00209   config->writeEntry("Id", mId);
00210   config->writeEntry( "PutRepliesInSameFolder", mPutRepliesInSameFolder );
00211   config->writeEntry( "IgnoreNewMail", mIgnoreNewMail );
00212   if ( !mShortcut.isNull() )
00213     config->writeEntry( "Shortcut", mShortcut.toString() );
00214   else
00215     config->deleteEntry( "Shortcut" );
00216 }
00217 
00218 KMFolderType KMFolder::folderType() const
00219 {
00220   return mStorage ? mStorage->folderType() : KMFolderTypeUnknown;
00221 }
00222 
00223 QString KMFolder::fileName() const
00224 {
00225   return mStorage ? mStorage->fileName() : QString::null;
00226 }
00227 
00228 QString KMFolder::location() const
00229 {
00230   return mStorage ? mStorage->location() : QString::null;
00231 }
00232 
00233 QString KMFolder::indexLocation() const
00234 {
00235   return mStorage ? mStorage->indexLocation() : QString::null;
00236 }
00237 
00238 QString KMFolder::subdirLocation() const
00239 {
00240   QString sLocation( path() );
00241 
00242   if( !sLocation.isEmpty() )
00243     sLocation += '/';
00244   sLocation += '.' + FolderStorage::dotEscape( fileName() ) + ".directory";
00245 
00246   return sLocation;
00247 }
00248 
00249 KMFolderDir* KMFolder::createChildFolder()
00250 {
00251   if( mChild )
00252     return mChild;
00253 
00254   QString childName = "." + fileName() + ".directory";
00255   QString childDir = path() + "/" + childName;
00256   if (access(QFile::encodeName(childDir), W_OK) != 0) // Not there or not writable
00257   {
00258     if (mkdir(QFile::encodeName(childDir), S_IRWXU) != 0
00259       && chmod(QFile::encodeName(childDir), S_IRWXU) != 0) {
00260       QString wmsg = QString(" '%1': %2").arg(childDir).arg(strerror(errno));
00261       KMessageBox::information(0,i18n("Failed to create folder") + wmsg);
00262       return 0;
00263     }
00264   }
00265 
00266   KMFolderDirType newType = KMStandardDir;
00267   if( folderType() == KMFolderTypeCachedImap )
00268     newType = KMDImapDir;
00269   else if( folderType() == KMFolderTypeImap )
00270     newType = KMImapDir;
00271 
00272   mChild = new KMFolderDir( this, parent(), childName, newType );
00273   if( !mChild )
00274     return 0;
00275   mChild->reload();
00276   parent()->append( mChild );
00277   return mChild;
00278 }
00279 
00280 void KMFolder::setChild( KMFolderDir* aChild )
00281 {
00282   mChild = aChild;
00283   mStorage->updateChildrenState();
00284 }
00285 
00286 bool KMFolder::noContent() const
00287 {
00288   return mStorage->noContent();
00289 }
00290 
00291 void KMFolder::setNoContent( bool aNoContent )
00292 {
00293   mStorage->setNoContent( aNoContent );
00294 }
00295 
00296 bool KMFolder::noChildren() const
00297 {
00298   return mStorage->noChildren();
00299 }
00300 
00301 void KMFolder::setNoChildren( bool aNoChildren )
00302 {
00303   mStorage->setNoChildren( aNoChildren );
00304 }
00305 
00306 KMMessage* KMFolder::getMsg( int idx )
00307 {
00308   return mStorage->getMsg( idx );
00309 }
00310 
00311 KMMsgInfo* KMFolder::unGetMsg( int idx )
00312 {
00313   return mStorage->unGetMsg( idx );
00314 }
00315 
00316 bool KMFolder::isMessage( int idx )
00317 {
00318   return mStorage->isMessage( idx );
00319 }
00320 
00321 QCString& KMFolder::getMsgString( int idx, QCString& mDest )
00322 {
00323   return mStorage->getMsgString( idx,  mDest );
00324 }
00325 
00326 DwString KMFolder::getDwString( int idx )
00327 {
00328   return mStorage->getDwString( idx );
00329 }
00330 
00331 void KMFolder::ignoreJobsForMessage( KMMessage* m )
00332 {
00333   mStorage->ignoreJobsForMessage( m );
00334 }
00335 
00336 FolderJob* KMFolder::createJob( KMMessage *msg, FolderJob::JobType jt,
00337                                 KMFolder *folder, QString partSpecifier,
00338                                 const AttachmentStrategy *as ) const
00339 {
00340   return mStorage->createJob( msg, jt, folder, partSpecifier, as );
00341 }
00342 
00343 FolderJob* KMFolder::createJob( QPtrList<KMMessage>& msgList,
00344                                 const QString& sets,
00345                                 FolderJob::JobType jt, KMFolder *folder ) const
00346 {
00347   return mStorage->createJob( msgList, sets, jt, folder );
00348 }
00349 
00350 const KMMsgBase* KMFolder::getMsgBase( int idx ) const
00351 {
00352   return mStorage->getMsgBase( idx );
00353 }
00354 
00355 KMMsgBase* KMFolder::getMsgBase( int idx )
00356 {
00357   return mStorage->getMsgBase( idx );
00358 }
00359 
00360 const KMMsgBase* KMFolder::operator[]( int idx ) const
00361 {
00362   return mStorage->operator[]( idx );
00363 }
00364 
00365 KMMsgBase* KMFolder::operator[]( int idx )
00366 {
00367   return mStorage->operator[]( idx );
00368 }
00369 
00370 KMMessage* KMFolder::take( int idx )
00371 {
00372   return mStorage->take( idx );
00373 }
00374 
00375 void KMFolder::take( QPtrList<KMMessage> msgList )
00376 {
00377   mStorage->take( msgList );
00378 }
00379 
00380 int KMFolder::addMsg( KMMessage* msg, int* index_return )
00381 {
00382   return mStorage->addMsg( msg, index_return );
00383 }
00384 
00385 int KMFolder::addMsgKeepUID( KMMessage* msg, int* index_return )
00386 {
00387   return mStorage->addMsgKeepUID( msg, index_return );
00388 }
00389 
00390 int KMFolder::addMsg( QPtrList<KMMessage>& list, QValueList<int>& index_return )
00391 {
00392   return mStorage->addMsg( list, index_return );
00393 }
00394 
00395 void KMFolder::emitMsgAddedSignals( int idx )
00396 {
00397   mStorage->emitMsgAddedSignals( idx );
00398 }
00399 
00400 void KMFolder::removeMsg( int i, bool imapQuiet )
00401 {
00402   mStorage->removeMsg( i, imapQuiet );
00403 }
00404 
00405 void KMFolder::removeMsg( QPtrList<KMMessage> msgList, bool imapQuiet )
00406 {
00407   mStorage->removeMsg( msgList, imapQuiet );
00408 }
00409 
00410 int KMFolder::expungeOldMsg( int days )
00411 {
00412   return mStorage->expungeOldMsg( days );
00413 }
00414 
00415 int KMFolder::moveMsg( KMMessage* msg, int* index_return )
00416 {
00417   return mStorage->moveMsg( msg, index_return );
00418 }
00419 
00420 int KMFolder::moveMsg(QPtrList<KMMessage> q, int* index_return )
00421 {
00422   return mStorage->moveMsg( q, index_return );
00423 }
00424 
00425 int KMFolder::find( const KMMsgBase* msg ) const
00426 {
00427   return mStorage->find( msg );
00428 }
00429 
00430 int KMFolder::find( const KMMessage* msg ) const
00431 {
00432   return mStorage->find( msg );
00433 }
00434 
00435 int KMFolder::count( bool cache ) const
00436 {
00437   return mStorage->count( cache );
00438 }
00439 
00440 int KMFolder::countUnread()
00441 {
00442   return mStorage->countUnread();
00443 }
00444 
00445 int KMFolder::countUnreadRecursive()
00446 {
00447   KMFolder *folder;
00448   int count = countUnread();
00449   KMFolderDir *dir = child();
00450   if (!dir)
00451     return count;
00452 
00453   QPtrListIterator<KMFolderNode> it(*dir);
00454   for ( ; it.current(); ++it )
00455     if (!it.current()->isDir()) {
00456       folder = static_cast<KMFolder*>(it.current());
00457       count += folder->countUnreadRecursive();
00458     }
00459 
00460   return count;
00461 }
00462 
00463 void KMFolder::msgStatusChanged( const KMMsgStatus oldStatus,
00464                                  const KMMsgStatus newStatus, int idx )
00465 {
00466   mStorage->msgStatusChanged( oldStatus, newStatus, idx );
00467 }
00468 
00469 int KMFolder::open()
00470 {
00471   return mStorage->open();
00472 }
00473 
00474 int KMFolder::canAccess()
00475 {
00476   return mStorage->canAccess();
00477 }
00478 
00479 void KMFolder::close( bool force )
00480 {
00481   mStorage->close( force );
00482 }
00483 
00484 void KMFolder::sync()
00485 {
00486   mStorage->sync();
00487 }
00488 
00489 bool KMFolder::isOpened() const
00490 {
00491   return mStorage->isOpened();
00492 }
00493 
00494 void KMFolder::markNewAsUnread()
00495 {
00496   mStorage->markNewAsUnread();
00497 }
00498 
00499 void KMFolder::markUnreadAsRead()
00500 {
00501   mStorage->markUnreadAsRead();
00502 }
00503 
00504 void KMFolder::remove()
00505 {
00506   mStorage->remove();
00507 }
00508 
00509 int KMFolder::expunge()
00510 {
00511   return mStorage->expunge();
00512 }
00513 
00514 int KMFolder::rename( const QString& newName, KMFolderDir *aParent )
00515 {
00516   return mStorage->rename( newName, aParent );
00517 }
00518 
00519 bool KMFolder::dirty() const
00520 {
00521   return mStorage->dirty();
00522 }
00523 
00524 void KMFolder::setDirty( bool f )
00525 {
00526   mStorage->setDirty( f );
00527 }
00528 
00529 bool KMFolder::needsCompacting() const
00530 {
00531   return mStorage->needsCompacting();
00532 }
00533 
00534 void KMFolder::setNeedsCompacting( bool f )
00535 {
00536   mStorage->setNeedsCompacting( f );
00537 }
00538 
00539 void KMFolder::quiet( bool beQuiet )
00540 {
00541   mStorage->quiet( beQuiet );
00542 }
00543 
00544 bool KMFolder::isReadOnly() const
00545 {
00546   return mStorage->isReadOnly();
00547 }
00548 
00549 QString KMFolder::label() const
00550 {
00551   if ( !mSystemLabel.isEmpty() )
00552      return mSystemLabel;
00553   if ( !mLabel.isEmpty() )
00554      return mLabel;
00555   if ( isSystemFolder() )
00556      return i18n( name().utf8() );
00557   return name();
00558 }
00559 
00560 //-----------------------------------------------------------------------------
00561 QString KMFolder::prettyURL() const
00562 {
00563   QString parentUrl;
00564   if ( parent() )
00565     parentUrl = parent()->prettyURL();
00566   if ( !parentUrl.isEmpty() )
00567     return parentUrl + '/' + label();
00568   else
00569     return label();
00570 }
00571 
00572 //--------------------------------------------------------------------------
00573 QString KMFolder::mailingListPostAddress() const
00574 {
00575   if ( mMailingList.features() & MailingList::Post ) {
00576     KURL::List::const_iterator it;
00577     KURL::List post = mMailingList.postURLS();
00578     for( it = post.begin(); it != post.end(); ++it ) {
00579       // We check for isEmpty because before 3.3 postAddress was just an
00580       // email@kde.org and that leaves protocol() field in the kurl class
00581       if ( (*it).protocol() == "mailto" || (*it).protocol().isEmpty() )
00582         return (*it).path();
00583     }
00584   }
00585   return QString::null;
00586 }
00587 
00588 void KMFolder::setMailingListEnabled( bool enabled )
00589 {
00590   mMailingListEnabled = enabled;
00591   mStorage->writeConfig();
00592 }
00593 
00594 void KMFolder::setMailingList( const MailingList& mlist )
00595 {
00596   mMailingList = mlist;
00597   mStorage->writeConfig();
00598 }
00599 
00600 void KMFolder::setIdentity( uint identity )
00601 {
00602   mIdentity = identity;
00603   kmkernel->slotRequestConfigSync();
00604 }
00605 
00606 void KMFolder::setWhoField(const QString& aWhoField )
00607 {
00608   mWhoField = aWhoField;
00609 #if 0
00610   // This isn't saved in the config anyway
00611   mStorage->writeConfig();
00612 #endif
00613 }
00614 
00615 void KMFolder::setUserWhoField( const QString& whoField, bool writeConfig )
00616 {
00617   if ( mUserWhoField == whoField )
00618     return;
00619   if ( whoField.isEmpty() )
00620   {
00621     // default setting
00622     const KPIM::Identity & identity =
00623       kmkernel->identityManager()->identityForUoidOrDefault( mIdentity );
00624 
00625     if ( isSystemFolder() && folderType() != KMFolderTypeImap ) {
00626       // local system folders
00627       if ( this == kmkernel->inboxFolder() ||
00628            this == kmkernel->trashFolder() )
00629         mWhoField = "From";
00630       if ( this == kmkernel->outboxFolder() ||
00631            this == kmkernel->sentFolder() ||
00632            this == kmkernel->draftsFolder() )
00633         mWhoField = "To";
00634     } else if ( identity.drafts() == idString()
00635                 || identity.fcc() == idString() )
00636       // drafts or sent of the identity
00637       mWhoField = "To";
00638     else
00639       mWhoField = "From";
00640   } else if ( whoField == "From" || whoField == "To" )
00641     // set the whoField according to the user-setting
00642     mWhoField = whoField;
00643   else {
00644     // this should not happen...
00645     kdDebug(5006) << "Illegal setting " << whoField << " for userWhoField!"
00646                   << endl;
00647     return; // don't use the value
00648   }
00649   mUserWhoField = whoField;
00650 
00651   if (writeConfig)
00652     mStorage->writeConfig();
00653   emit viewConfigChanged();
00654 }
00655 
00656 void KMFolder::correctUnreadMsgsCount()
00657 {
00658   mStorage->correctUnreadMsgsCount();
00659 }
00660 
00661 QString KMFolder::idString() const
00662 {
00663   KMFolderNode* folderNode = parent();
00664   if (!folderNode)
00665     return "";
00666   while ( folderNode->parent() )
00667     folderNode = folderNode->parent();
00668   QString myPath = path();
00669   int pathLen = myPath.length() - folderNode->path().length();
00670   QString relativePath = myPath.right( pathLen );
00671   if (!relativePath.isEmpty())
00672     relativePath = relativePath.right( relativePath.length() - 1 ) + "/";
00673   QString escapedName = name();
00674   /* Escape [ and ] as they are disallowed for kconfig sections and that is
00675      what the idString is primarily used for. */
00676   escapedName.replace( "[", "%(" );
00677   escapedName.replace( "]", "%)" );
00678   return relativePath + escapedName;
00679 }
00680 
00681 void KMFolder::setAutoExpire( bool enabled )
00682 {
00683   if( enabled != mExpireMessages ) {
00684     mExpireMessages = enabled;
00685     mStorage->writeConfig();
00686   }
00687 }
00688 
00689 void KMFolder::setUnreadExpireAge( int age )
00690 {
00691   if( age >= 0 && age != mUnreadExpireAge ) {
00692     mUnreadExpireAge = age;
00693     mStorage->writeConfig();
00694   }
00695 }
00696 
00697 void KMFolder::setUnreadExpireUnits( ExpireUnits units )
00698 {
00699   if (units >= expireNever && units < expireMaxUnits)
00700     mUnreadExpireUnits = units;
00701 }
00702 
00703 void KMFolder::setReadExpireAge( int age )
00704 {
00705   if( age >= 0 && age != mReadExpireAge ) {
00706     mReadExpireAge = age;
00707     mStorage->writeConfig();
00708   }
00709 }
00710 
00711 void KMFolder::setReadExpireUnits( ExpireUnits units )
00712 {
00713   if (units >= expireNever && units <= expireMaxUnits)
00714     mReadExpireUnits = units;
00715 }
00716 
00717 
00718 void KMFolder::setExpireAction( ExpireAction a )
00719 {
00720   if ( a != mExpireAction ) {
00721     mExpireAction = a;
00722     mStorage->writeConfig();
00723   }
00724 }
00725 
00726 void KMFolder::setExpireToFolderId( const QString& id )
00727 {
00728   if ( id != mExpireToFolderId ) {
00729     mExpireToFolderId = id;
00730     mStorage->writeConfig();
00731   }
00732 }
00733 
00734 
00735 static int daysToExpire( int number, ExpireUnits units )
00736 {
00737   switch (units) {
00738   case expireDays: // Days
00739     return number;
00740   case expireWeeks: // Weeks
00741     return number * 7;
00742   case expireMonths: // Months - this could be better rather than assuming 31day months.
00743     return number * 31;
00744   default: // this avoids a compiler warning (not handled enumeration values)
00745     ;
00746   }
00747   return -1;
00748 }
00749 
00750 void KMFolder::daysToExpire(int& unreadDays, int& readDays) {
00751   unreadDays = ::daysToExpire( getUnreadExpireAge(), getUnreadExpireUnits() );
00752   readDays = ::daysToExpire( getReadExpireAge(), getReadExpireUnits() );
00753 }
00754 
00755 void KMFolder::expireOldMessages( bool immediate )
00756 {
00757   KMail::ScheduledExpireTask* task = new KMail::ScheduledExpireTask(this, immediate);
00758   kmkernel->jobScheduler()->registerTask( task );
00759   if ( immediate ) {
00760     // #82259: compact after expiring.
00761     compact( CompactLater );
00762   }
00763 }
00764 
00765 void KMFolder::compact( CompactOptions options )
00766 {
00767   if ( options == CompactLater ) {
00768     KMail::ScheduledCompactionTask* task = new KMail::ScheduledCompactionTask(this, false);
00769     kmkernel->jobScheduler()->registerTask( task );
00770   } else {
00771     mStorage->compact( options == CompactSilentlyNow );
00772   }
00773 }
00774 
00775 KMFolder* KMFolder::trashFolder() const
00776 {
00777   return mStorage ? mStorage->trashFolder() : 0;
00778 }
00779 
00780 int KMFolder::writeIndex( bool createEmptyIndex )
00781 {
00782   return mStorage->writeIndex( createEmptyIndex );
00783 }
00784 
00785 void KMFolder::setStatus( int idx, KMMsgStatus status, bool toggle )
00786 {
00787   mStorage->setStatus( idx, status, toggle );
00788 }
00789 
00790 void KMFolder::setStatus( QValueList<int>& ids, KMMsgStatus status,
00791                           bool toggle )
00792 {
00793   mStorage->setStatus( ids, status, toggle);
00794 }
00795 
00796 void KMFolder::setIconPaths( const QString &normalPath,
00797                              const QString &unreadPath )
00798 {
00799   mNormalIconPath = normalPath;
00800   mUnreadIconPath = unreadPath;
00801   mStorage->writeConfig();
00802   emit iconsChanged();
00803 }
00804 
00805 void KMFolder::removeJobs()
00806 {
00807   mStorage->removeJobs();
00808 }
00809 
00810 int KMFolder::updateIndex()
00811 {
00812   return mStorage->updateIndex();
00813 }
00814 
00815 void KMFolder::reallyAddMsg( KMMessage* aMsg )
00816 {
00817   mStorage->reallyAddMsg( aMsg );
00818 }
00819 
00820 void KMFolder::reallyAddCopyOfMsg( KMMessage* aMsg )
00821 {
00822   mStorage->reallyAddCopyOfMsg( aMsg );
00823 }
00824 
00825 void KMFolder::setShortcut( const KShortcut &sc )
00826 {
00827   if ( mShortcut != sc ) {
00828     mShortcut = sc;
00829     emit shortcutChanged( this );
00830   }
00831 }
00832 
00833 bool KMFolder::isMoveable() const
00834 {
00835   return mStorage->isMoveable();
00836 }
00837 
00838 void KMFolder::slotContentsTypeChanged( KMail::FolderContentsType type )
00839 {
00840   kmkernel->iCalIface().folderContentsTypeChanged( this, type );
00841   emit iconsChanged();
00842 }
00843 
00844 #include "kmfolder.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys