23 #include "kmfolderdir.h"
24 #include "kmfoldermbox.h"
25 #include "folderstorage.h"
26 #include "kmfoldercachedimap.h"
27 #include "kmfoldersearch.h"
28 #include "kmfolderimap.h"
29 #include "kmfoldermgr.h"
30 #include <libkpimidentities/identitymanager.h>
31 #include <libkpimidentities/identity.h>
32 #include "expirejob.h"
33 #include "compactionjob.h"
34 #include "kmfoldertree.h"
35 #include "kmailicalifaceimpl.h"
36 #include "kmaccount.h"
41 #include <tdelocale.h>
42 #include <tdeshortcut.h>
43 #include <tdemessagebox.h>
45 #include <tqfileinfo.h>
49 KMFolderType aFolderType,
bool withIndex,
bool exportedSernums )
50 : KMFolderNode( aParent, aFolderName ), mStorage(0),
52 mIsSystemFolder( false ),
53 mHasIndex( withIndex ),
54 mExportsSernums( exportedSernums ),
55 mMoveInProgress( false ),
56 mExpireMessages( false ), mUnreadExpireAge( 28 ),
57 mReadExpireAge( 14 ), mUnreadExpireUnits( expireNever ),
58 mReadExpireUnits( expireNever ),
59 mExpireAction( ExpireDelete ),
60 mUseCustomIcons( false ), mMailingListEnabled( false ),
63 mPutRepliesInSameFolder( false ),
64 mIgnoreNewMail( false )
66 if( aFolderType == KMFolderTypeCachedImap )
67 mStorage =
new KMFolderCachedImap(
this, aFolderName.latin1() );
68 else if( aFolderType == KMFolderTypeImap )
69 mStorage =
new KMFolderImap(
this, aFolderName.latin1() );
70 else if( aFolderType == KMFolderTypeMaildir )
71 mStorage =
new KMFolderMaildir(
this, aFolderName.latin1() );
72 else if( aFolderType == KMFolderTypeSearch )
73 mStorage =
new KMFolderSearch(
this, aFolderName.latin1() );
75 mStorage =
new KMFolderMbox(
this, aFolderName.latin1() );
80 dirinfo.setFile( mStorage->location() );
81 if ( !dirinfo.exists() ) {
82 int rc = mStorage->create();
83 TQString msg = i18n(
"<qt>Error while creating file <b>%1</b>:<br>%2</qt>").arg(aFolderName).arg(strerror(rc));
85 KMessageBox::information(0, msg);
98 connect( mStorage, TQT_SIGNAL( invalidated(
KMFolder* ) ),
99 parent()->manager(), TQT_SIGNAL( folderInvalidated(
KMFolder* ) ) );
103 connect( mStorage, TQT_SIGNAL(
changed() ), TQT_SIGNAL(
changed() ) );
104 connect( mStorage, TQT_SIGNAL(
cleared() ), TQT_SIGNAL(
cleared() ) );
110 connect( mStorage, TQT_SIGNAL(
msgRemoved(
int, TQString ) ),
114 connect( mStorage, TQT_SIGNAL(
msgAdded(
int ) ), TQT_SIGNAL(
msgAdded(
int ) ) );
121 connect( mStorage, TQT_SIGNAL(
statusMsg(
const TQString& ) ),
122 TQT_SIGNAL(
statusMsg(
const TQString& ) ) );
132 connect( mStorage, TQT_SIGNAL( contentsTypeChanged( KMail::FolderContentsType ) ),
133 this, TQT_SLOT( slotContentsTypeChanged( KMail::FolderContentsType ) ) );
136 this, TQT_SLOT( slotFolderSizeChanged() ) );
141 mStorage->readConfig();
144 if ( mExportsSernums )
145 mStorage->registerWithMessageDict();
147 mStorage->setAutoCreateIndex(
false );
149 if ( mId == 0 && aParent )
150 mId = aParent->
manager()->createId();
153 KMFolder::~KMFolder()
155 mStorage->
close(
"~KMFolder",
true );
163 if ( !config->readEntry(
"SystemLabel").isEmpty() )
164 mSystemLabel = config->readEntry(
"SystemLabel");
165 mExpireMessages = config->readBoolEntry(
"ExpireMessages",
false);
166 mReadExpireAge = config->readNumEntry(
"ReadExpireAge", 3);
167 mReadExpireUnits = (ExpireUnits)config->readNumEntry(
"ReadExpireUnits", expireMonths);
168 mUnreadExpireAge = config->readNumEntry(
"UnreadExpireAge", 12);
169 mUnreadExpireUnits = (ExpireUnits)config->readNumEntry(
"UnreadExpireUnits", expireNever);
170 mExpireAction = config->readEntry(
"ExpireAction",
"Delete") ==
"Move" ? ExpireMove : ExpireDelete;
171 mExpireToFolderId = config->readEntry(
"ExpireToFolder");
173 mUseCustomIcons = config->readBoolEntry(
"UseCustomIcons",
false );
174 mNormalIconPath = config->readEntry(
"NormalIconPath" );
175 mUnreadIconPath = config->readEntry(
"UnreadIconPath" );
177 mMailingListEnabled = config->readBoolEntry(
"MailingListEnabled");
178 mMailingList.readConfig( config );
180 mIdentity = config->readUnsignedNumEntry(
"Identity",0);
182 setUserWhoField( config->readEntry(
"WhoField"), false );
183 uint savedId = config->readUnsignedNumEntry(
"Id", 0);
185 if ( savedId != 0 && mId == 0 )
187 mPutRepliesInSameFolder = config->readBoolEntry(
"PutRepliesInSameFolder",
false );
188 mIgnoreNewMail = config->readBoolEntry(
"IgnoreNewMail",
false );
190 if ( mUseCustomIcons )
193 TQString shortcut( config->readEntry(
"Shortcut" ) );
194 if ( !shortcut.isEmpty() ) {
195 TDEShortcut sc( shortcut );
202 config->writeEntry(
"SystemLabel", mSystemLabel);
203 config->writeEntry(
"ExpireMessages", mExpireMessages);
204 config->writeEntry(
"ReadExpireAge", mReadExpireAge);
205 config->writeEntry(
"ReadExpireUnits", mReadExpireUnits);
206 config->writeEntry(
"UnreadExpireAge", mUnreadExpireAge);
207 config->writeEntry(
"UnreadExpireUnits", mUnreadExpireUnits);
208 config->writeEntry(
"ExpireAction", mExpireAction == ExpireDelete ?
"Delete" :
"Move");
209 config->writeEntry(
"ExpireToFolder", mExpireToFolderId);
211 config->writeEntry(
"UseCustomIcons", mUseCustomIcons);
212 config->writeEntry(
"NormalIconPath", mNormalIconPath);
213 config->writeEntry(
"UnreadIconPath", mUnreadIconPath);
215 config->writeEntry(
"MailingListEnabled", mMailingListEnabled);
216 mMailingList.writeConfig( config );
218 if ( mIdentity != 0 && ( !mStorage || !mStorage->account() || mIdentity != mStorage->account()->identityId() ) )
219 config->writeEntry(
"Identity", mIdentity);
221 config->deleteEntry(
"Identity");
223 config->writeEntry(
"WhoField", mUserWhoField);
224 config->writeEntry(
"Id", mId);
225 config->writeEntry(
"PutRepliesInSameFolder", mPutRepliesInSameFolder );
226 config->writeEntry(
"IgnoreNewMail", mIgnoreNewMail );
227 if ( !mShortcut.isNull() )
228 config->writeEntry(
"Shortcut", mShortcut.toString() );
230 config->deleteEntry(
"Shortcut" );
235 return mStorage ? mStorage->
folderType() : KMFolderTypeUnknown;
240 return mStorage ? mStorage->
fileName() : TQString();
245 return mStorage ? mStorage->
location() : TQString();
255 TQString sLocation( path() );
257 if( !sLocation.isEmpty() )
269 TQString childName =
"." +
fileName() +
".directory";
270 TQString childDir = path() +
"/" + childName;
271 if (access(TQFile::encodeName(childDir), W_OK) != 0)
273 if (mkdir(TQFile::encodeName(childDir), S_IRWXU) != 0
274 && chmod(TQFile::encodeName(childDir), S_IRWXU) != 0) {
275 TQString wmsg = TQString(
" '%1': %2").arg(childDir).arg(strerror(errno));
276 KMessageBox::information(0,i18n(
"Failed to create folder") + wmsg);
281 KMFolderDirType newType = KMStandardDir;
283 newType = KMDImapDir;
287 mChild =
new KMFolderDir(
this, parent(), childName, newType );
291 parent()->append( mChild );
303 return mStorage ? mStorage->
noContent() :
true;
323 return mStorage->
getMsg( idx );
347 KMFolder *folder, TQString partSpecifier,
348 const AttachmentStrategy *as )
const
350 return mStorage->
createJob( msg, jt, folder, partSpecifier, as );
354 const TQString& sets,
355 FolderJob::JobType jt,
KMFolder *folder )
const
357 return mStorage->
createJob( msgList, sets, jt, folder );
372 return mStorage->operator[]( idx );
377 return mStorage->operator[]( idx );
382 return mStorage->
take( idx );
387 mStorage->
take( msgList );
392 return mStorage->
addMsg( msg, index_return );
402 return mStorage->
addMsg( list, index_return );
417 mStorage->
removeMsg( msgList, imapQuiet );
427 return mStorage->
moveMsg( msg, index_return );
432 return mStorage->
moveMsg( q, index_return );
437 return mStorage ? mStorage->
find( msg ) : -1;
442 return mStorage ? mStorage->
find( msg ) : -1;
447 return mStorage->
count( cache );
463 TQPtrListIterator<KMFolderNode> it(*dir);
464 for ( ; it.current(); ++it )
465 if (!it.current()->isDir()) {
466 folder =
static_cast<KMFolder*
>(it.current());
474 const KMMsgStatus newStatus,
int idx )
481 return mStorage->
open(owner);
492 mStorage->
close( owner, force );
522 mStorage->
open(
"kmfolder_remove");
533 return mStorage->
rename( newName, aParent );
538 return mStorage->
dirty();
551 void KMFolder::setNeedsCompacting(
bool f )
553 mStorage->setNeedsCompacting( f );
558 mStorage->
quiet( beQuiet );
566 bool KMFolder::mailCheckInProgress()
const
568 return mStorage->mailCheckInProgress();
583 if ( !mSystemLabel.isEmpty() )
585 if ( !mLabel.isEmpty() )
588 return i18n( name().utf8() );
597 parentUrl = parent()->prettyURL();
598 if ( !parentUrl.isEmpty() )
599 return parentUrl +
'/' +
label();
605 TQString KMFolder::mailingListPostAddress()
const
607 if ( mMailingList.features() & MailingList::Post ) {
608 KURL::List::const_iterator it;
609 KURL::List post = mMailingList.postURLS();
610 for( it = post.begin(); it != post.end(); ++it ) {
613 if ( (*it).protocol() ==
"mailto" || (*it).protocol().isEmpty() )
622 mMailingListEnabled = enabled;
626 void KMFolder::setMailingList(
const MailingList& mlist )
628 mMailingList = mlist;
632 void KMFolder::setIdentity( uint identity )
634 mIdentity = identity;
635 kmkernel->slotRequestConfigSync();
638 uint KMFolder::identity()
const
641 kdDebug() <<
"FOO: " << mIdentity <<
" :: " << mStorage << endl;
642 if ( !mIdentity && mStorage )
643 if ( KMAccount *act = mStorage->account() )
644 return act->identityId();
648 void KMFolder::setWhoField(
const TQString& aWhoField )
650 mWhoField = aWhoField;
657 void KMFolder::setUserWhoField(
const TQString& whoField,
bool writeConfig )
659 if ( mUserWhoField == whoField )
661 if ( whoField.isEmpty() )
664 const KPIM::Identity & identity =
665 kmkernel->identityManager()->identityForUoidOrDefault( mIdentity );
669 if (
this == kmkernel->inboxFolder() ||
670 this == kmkernel->trashFolder() )
672 if (
this == kmkernel->outboxFolder() ||
673 this == kmkernel->sentFolder() ||
674 this == kmkernel->draftsFolder() ||
675 this == kmkernel->templatesFolder() )
677 }
else if ( identity.drafts() ==
idString() ||
678 identity.templates() ==
idString() ||
684 }
else if ( whoField ==
"From" || whoField ==
"To" )
689 kdDebug(5006) <<
"Illegal setting " << whoField <<
" for userWhoField!"
707 KMFolderNode* folderNode = parent();
710 while ( folderNode->parent() )
711 folderNode = folderNode->parent();
712 TQString myPath = path();
713 int pathLen = myPath.length() - folderNode->path().length();
714 TQString relativePath = myPath.right( pathLen );
715 if (!relativePath.isEmpty())
716 relativePath = relativePath.right( relativePath.length() - 1 ) +
"/";
717 TQString escapedName = name();
720 escapedName.replace(
"[",
"%(" );
721 escapedName.replace(
"]",
"%)" );
722 return relativePath + escapedName;
727 if( enabled != mExpireMessages ) {
728 mExpireMessages = enabled;
735 if( age >= 0 && age != mUnreadExpireAge ) {
736 mUnreadExpireAge = age;
743 if (units >= expireNever && units < expireMaxUnits)
744 mUnreadExpireUnits = units;
750 if( age >= 0 && age != mReadExpireAge ) {
751 mReadExpireAge = age;
758 if (units >= expireNever && units <= expireMaxUnits)
759 mReadExpireUnits = units;
764 void KMFolder::setExpireAction( ExpireAction a )
766 if ( a != mExpireAction ) {
772 void KMFolder::setExpireToFolderId(
const TQString&
id )
774 if (
id != mExpireToFolderId ) {
775 mExpireToFolderId = id;
781 static int daysToExpire(
int number, ExpireUnits units )
796 void KMFolder::daysToExpire(
int& unreadDays,
int& readDays) {
804 kmkernel->jobScheduler()->registerTask( task );
813 if ( options == CompactLater ) {
815 kmkernel->jobScheduler()->registerTask( task );
817 mStorage->
compact( options == CompactSilentlyNow );
828 return mStorage->
writeIndex( createEmptyIndex );
833 mStorage->
setStatus( idx, status, toggle );
839 mStorage->
setStatus( ids, status, toggle);
842 void KMFolder::setIconPaths(
const TQString &normalPath,
843 const TQString &unreadPath )
845 mNormalIconPath = normalPath;
846 mUnreadIconPath = unreadPath;
851 void KMFolder::removeJobs()
853 mStorage->removeJobs();
871 void KMFolder::setShortcut(
const TDEShortcut &sc )
873 if ( mShortcut != sc ) {
884 void KMFolder::slotContentsTypeChanged( KMail::FolderContentsType type )
886 kmkernel->iCalIface().folderContentsTypeChanged(
this, type );
890 void KMFolder::slotFolderSizeChanged()
893 KMFolder* papa = parent()->manager()->parentFolder(
this );
894 if ( papa && papa !=
this ) {
895 papa->slotFolderSizeChanged();
904 if ( folderName.find(
'/' ) != -1 &&
905 fldType != KMFolderTypeImap &&
906 fldType != KMFolderTypeCachedImap ) {
907 message = i18n(
"Folder names cannot contain the / (slash) character; please choose another folder name." );
912 if ( folderName.startsWith(
"." ) ) {
913 message = i18n(
"Folder names cannot start with a . (dot) character; please choose another folder name." );
918 if ( fldType == KMFolderTypeImap || fldType == KMFolderTypeCachedImap ) {
920 if ( fldType == KMFolderTypeImap ) {
921 KMAcctImap *ai =
static_cast<KMFolderImap*
>( mStorage )->account();
923 delimiter = ai->delimiterForFolder( mStorage );
926 KMAcctCachedImap *ai =
static_cast<KMFolderCachedImap*
>( mStorage )->account();
928 delimiter = ai->delimiterForFolder( mStorage );
931 if ( !delimiter.isEmpty() && folderName.find( delimiter ) != -1 ) {
932 message = i18n(
"Your IMAP server does not allow the character '%1'; please choose another folder name." ).arg( delimiter );
939 #include "kmfolder.moc"