kmail

kmfoldercachedimap.h
1/*
2 * kmfoldercachedimap.cpp
3 *
4 * Copyright (c) 2002-2004 Bo Thorsen <bo@sonofthor.dk>
5 * Copyright (c) 2002-2003 Steffen Hansen <steffen@klaralvdalens-datakonsult.se>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 * In addition, as a special exception, the copyright holders give
21 * permission to link the code of this program with any edition of
22 * the TQt library by Trolltech AS, Norway (or with modified versions
23 * of TQt that use the same license as TQt), and distribute linked
24 * combinations including the two. You must obey the GNU General
25 * Public License in all respects for all of the code used other than
26 * TQt. If you modify this file, you may extend this exception to
27 * your version of the file, but you are not obligated to do so. If
28 * you do not wish to do so, delete this exception statement from
29 * your version.
30 */
31
32#ifndef kmfoldercachedimap_h
33#define kmfoldercachedimap_h
34
35#include <kdialogbase.h>
36#include <tdestandarddirs.h>
37#include <tqvaluelist.h>
38#include <tqvaluevector.h>
39#include <tqptrlist.h>
40#include <tqdialog.h>
41
42#include "kmfoldermaildir.h"
43#include "kmfolderimap.h"
44#include "kmacctcachedimap.h"
45#include "kmfoldertype.h"
46#include "folderjob.h"
47#include "cachedimapjob.h"
48#include "quotajobs.h"
49
50#include <set>
51
52using KMail::FolderJob;
53using KMail::QuotaInfo;
54class KMCommand;
55
56class TQComboBox;
57class TQRadioButton;
58
59namespace KMail {
60 class AttachmentStrategy;
61 class ImapAccountBase;
62 struct ACLListEntry;
63}
64using KMail::AttachmentStrategy;
65
66class DImapTroubleShootDialog : public KDialogBase
67{
68 TQ_OBJECT
69
70public:
71 enum SelectedOperation {
72 None = -1,
73 ReindexCurrent = 0,
74 ReindexRecursive = 1,
75 ReindexAll = 2,
76 RefreshCache
77 };
78
79 DImapTroubleShootDialog( TQWidget* parent=0, const char* name=0 );
80
81 static int run();
82
83private slots:
84 void slotDone();
85 void slotChanged();
86private:
87 TQRadioButton *mIndexButton, *mCacheButton;
88 TQComboBox *mIndexScope;
89 TQButtonGroup *mButtonGroup;
90 int rc;
91};
92
93class KMFolderCachedImap : public KMFolderMaildir
94{
95 TQ_OBJECT
96
97
98public:
99 static TQString cacheLocation() {
100 return locateLocal("data", "kmail/dimap" );
101 }
102
106 KMFolderCachedImap(KMFolder* folder, const char* name=0);
107 virtual ~KMFolderCachedImap();
108
110 void reallyDoClose(const char* owner);
111
113 void initializeFrom( KMFolderCachedImap* parent );
114
115 virtual void readConfig();
116 virtual void writeConfig();
117
118 void writeConfigKeysWhichShouldNotGetOverwrittenByReadConfig();
119
121 virtual KMFolderType folderType() const { return KMFolderTypeCachedImap; }
122
124 virtual int create();
125
127 virtual void remove();
128
130 virtual void serverSync( bool recurse, bool quotaOnly = false );
131
133 void resetSyncState( );
134
138 void setAlarmsBlocked( bool blocked );
140 bool alarmsBlocked() const;
141
142 void checkUidValidity();
143
144 enum imapState { imapNoInformation=0, imapInProgress=1, imapFinished=2 };
145
146 virtual imapState getContentState() const { return mContentState; }
147 virtual void setContentState(imapState state) { mContentState = state; }
148
149 virtual imapState getSubfolderState() { return mSubfolderState; }
150 virtual void setSubfolderState(imapState state);
151
153 void setImapPath(const TQString &path);
154 TQString imapPath() const { return mImapPath; }
155
157 void setLastUid( ulong uid );
158 ulong lastUid();
159
161 KMMsgBase* findByUID( ulong uid );
162
164 void setUidValidity(const TQString &validity) { mUidValidity = validity; }
165 TQString uidValidity() const { return mUidValidity; }
166
169 void clearUidMap() { uidMap.clear(); }
170
172 void setAccount(KMAcctCachedImap *acct);
173 KMAcctCachedImap* account() const;
174
176 TQString uidCacheLocation() const;
177
179 int readUidCache();
180
182 int writeUidCache();
183
185 int progress() const { return mProgress; }
186
187 /* Reimplemented from KMFolder. Moving is not supported, so aParent must be 0 */
188 virtual int rename(const TQString& aName, KMFolderDir *aParent=0);
189
195 virtual KMMessage* take(int idx);
196
202 void takeTemporarily( int idx );
203
204 /* Reimplemented from KMFolderMaildir */
205 virtual int addMsg(KMMessage* msg, int* index_return = 0);
206 /* internal version that doesn't remove the X-UID header */
207 virtual int addMsgInternal(KMMessage* msg, bool, int* index_return = 0);
208 virtual int addMsgKeepUID(KMMessage* msg, int* index_return = 0) {
209 return addMsgInternal(msg, false, index_return);
210 }
211
212 /* Reimplemented from KMFolderMaildir */
213 virtual void removeMsg(int i, bool imapQuiet = false);
214 virtual void removeMsg( const TQPtrList<KMMsgBase> & msgList, bool imapQuiet = false)
215 { FolderStorage::removeMsg(msgList, imapQuiet); }
216
218 bool isReadOnly() const { return KMFolderMaildir::isReadOnly() || mReadOnly; }
219 bool canDeleteMessages() const;
220
221
225 void sendFolderComplete(bool success)
226 { emit folderComplete(this, success); }
227
231 void setSilentUpload( bool silent ) { mSilentUpload = silent; }
232 bool silentUpload() { return mSilentUpload; }
233
234 virtual int createIndexFromContents() {
235 const int result = KMFolderMaildir::createIndexFromContents();
236 reloadUidMap();
237 return result;
238 }
239
240 int createIndexFromContentsRecursive();
241
242 //virtual void holdSyncs( bool hold ) { mHoldSyncs = hold; }
243
249 virtual bool listDirectory();
250
251 virtual void listNamespaces();
252
254 KMFolder* trashFolder() const;
255
261 int userRights() const { return mUserRights; }
262 KMail::ACLJobs::ACLFetchState userRightsState() const { return mUserRightsState; }
263
265 void setUserRights( unsigned int userRights, KMail::ACLJobs::ACLFetchState state );
266
276 const QuotaInfo quotaInfo() const { return mQuotaInfo; }
277 void setQuotaInfo( const QuotaInfo & );
278
280 typedef TQValueVector<KMail::ACLListEntry> ACLList;
281 const ACLList& aclList() const { return mACLList; }
282 KMail::ACLJobs::ACLFetchState aclListState() const { return mACLListState; };
283
285 void setACLList( const ACLList& arr );
286
287 // Reimplemented so the mStatusChangedLocally bool can be set
288 virtual void setStatus( int id, KMMsgStatus status, bool toggle );
289 virtual void setStatus( TQValueList<int>& ids, KMMsgStatus status, bool toggle );
290
291 TQString annotationFolderType() const { return mAnnotationFolderType; }
292
293 // For kmailicalifaceimpl only
294 void updateAnnotationFolderType();
295
304 enum IncidencesFor { IncForNobody, IncForAdmins, IncForReaders };
305
306 IncidencesFor incidencesFor() const { return mIncidencesFor; }
308 void setIncidencesFor( IncidencesFor incfor );
309
311 bool sharedSeenFlags() const { return mSharedSeenFlags; }
313 void setSharedSeenFlags( bool b );
314
316 virtual bool isMoveable() const;
317
322 TQStringList namespacesToList() { return mNamespacesToList; }
323 void setNamespacesToList( TQStringList list ) { mNamespacesToList = list; }
324
329 const TQString& imapPathForCreation() { return mImapPathCreation; }
330 void setImapPathForCreation( const TQString& path ) { mImapPathCreation = path; }
331
333 bool isCloseToQuota() const;
334
336 int permanentFlags() const { return mPermanentFlags; }
337
338
339 TQString folderAttributes() const { return mFolderAttributes; }
340
341 virtual bool mailCheckInProgress() const;
342
343protected slots:
344 void slotGetMessagesData(TDEIO::Job * job, const TQByteArray & data);
345 void getMessagesResult(KMail::FolderJob *, bool lastSet);
346 void slotGetLastMessagesResult(KMail::FolderJob *);
347 void slotProgress(unsigned long done, unsigned long total);
348 void slotPutProgress( unsigned long, unsigned long );
349
350 //virtual void slotCheckValidityResult(TDEIO::Job * job);
351 void slotSubFolderComplete(KMFolderCachedImap*, bool);
352 void slotSubFolderCloseToQuotaChanged();
353
354 // Connected to the imap account
355 void slotConnectionResult( int errorCode, const TQString& errorMsg );
356
357 void slotCheckUidValidityResult( KMail::FolderJob* job );
358 void slotPermanentFlags( int flags );
359 void slotTestAnnotationResult(TDEIO::Job *job);
360 void slotGetAnnotationResult( TDEIO::Job* );
361 void slotMultiUrlGetAnnotationResult( TDEIO::Job* );
362 void slotSetAnnotationResult(TDEIO::Job *job);
363 void slotReceivedUserRights( KMFolder* );
364 void slotReceivedACL( KMFolder*, TDEIO::Job*, const KMail::ACLList& );
365
366 void slotMultiSetACLResult(TDEIO::Job *);
367 void slotACLChanged( const TQString&, int );
368 void slotAnnotationResult(const TQString& entry, const TQString& value, bool found);
369 void slotAnnotationChanged( const TQString& entry, const TQString& attribute, const TQString& value );
370 void slotDeleteMessagesResult(KMail::FolderJob *);
371 void slotImapStatusChanged(KMFolder* folder, const TQString&, bool);
372 void slotStorageQuotaResult( const QuotaInfo& );
373 void slotQuotaResult( TDEIO::Job* job );
374
375protected:
376 /* returns true if there were messages to delete
377 on the server */
378 bool deleteMessages();
379 void listMessages();
380 void uploadNewMessages();
381 void uploadFlags();
382 void uploadSeenFlags();
383 void createNewFolders();
384
385 void listDirectory2();
386 void createFoldersNewOnServerAndFinishListing( const TQValueVector<int> foldersNewOnServer );
387
388
391 virtual TQValueList<unsigned long> findNewMessages();
394 virtual TQValueList<KMFolderCachedImap*> findNewFolders();
395
397 virtual bool canRemoveFolder() const;
398
400 virtual FolderJob* doCreateJob( KMMessage *msg, FolderJob::JobType jt, KMFolder *folder,
401 TQString partSpecifier, const AttachmentStrategy *as ) const;
402 virtual FolderJob* doCreateJob( TQPtrList<KMMessage>& msgList, const TQString& sets,
403 FolderJob::JobType jt, KMFolder *folder ) const;
404
405 virtual void timerEvent( TQTimerEvent* );
406
407 /* update progress status */
408 void newState( int progress, const TQString& syncStatus );
409
411 KMFolderCachedImap* findParent( const TQString& path, const TQString& name );
412
413
414
415public slots:
419 void slotSimpleData(TDEIO::Job * job, const TQByteArray & data);
420
424 void slotTroubleshoot();
425
430 void slotListResult( const TQStringList&, const TQStringList&,
431 const TQStringList&, const TQStringList&, const ImapAccountBase::jobData& );
432
437 void slotCheckNamespace( const TQStringList&, const TQStringList&,
438 const TQStringList&, const TQStringList&, const ImapAccountBase::jobData& );
439
440private slots:
441 void serverSyncInternal();
442 void slotIncreaseProgress();
443 void slotUpdateLastUid();
444 void slotFolderDeletionOnServerFinished();
445 void slotRescueDone( KMCommand* command );
446 void slotRenameFolderFinished();
447
448signals:
449 void folderComplete(KMFolderCachedImap *folder, bool success);
450 void listComplete( KMFolderCachedImap* );
451
455 void closeToQuotaChanged();
456
457private:
458 void setReadOnly( bool readOnly );
459 TQString state2String( int state ) const;
460 void rememberDeletion( int );
465 KMCommand* rescueUnsyncedMessages();
467 void rescueUnsyncedMessagesAndDeleteFolder( KMFolder *folder, bool root = true );
468
473 void disconnectSubFolderSignals();
474
480 void syncNextSubFolder( bool secondSync );
481
485 void buildSubFolderList();
486
488 enum {
489 SYNC_STATE_INITIAL,
490 SYNC_STATE_TEST_ANNOTATIONS,
491 SYNC_STATE_PUT_MESSAGES,
492 SYNC_STATE_UPLOAD_FLAGS,
493 SYNC_STATE_CREATE_SUBFOLDERS,
494 SYNC_STATE_LIST_NAMESPACES,
495 SYNC_STATE_LIST_SUBFOLDERS,
496 SYNC_STATE_LIST_SUBFOLDERS2,
497 SYNC_STATE_DELETE_SUBFOLDERS,
498 SYNC_STATE_LIST_MESSAGES,
499 SYNC_STATE_DELETE_MESSAGES,
500 SYNC_STATE_EXPUNGE_MESSAGES,
501 SYNC_STATE_GET_MESSAGES,
502 SYNC_STATE_HANDLE_INBOX,
503 SYNC_STATE_GET_USERRIGHTS,
504 SYNC_STATE_GET_ANNOTATIONS,
505 SYNC_STATE_SET_ANNOTATIONS,
506 SYNC_STATE_GET_ACLS,
507 SYNC_STATE_SET_ACLS,
508 SYNC_STATE_GET_QUOTA,
509 SYNC_STATE_FIND_SUBFOLDERS,
510 SYNC_STATE_SYNC_SUBFOLDERS,
511 SYNC_STATE_CHECK_UIDVALIDITY,
512 SYNC_STATE_RENAME_FOLDER,
513 SYNC_STATE_CLOSE,
514 SYNC_STATE_GET_SUBFOLDER_QUOTA
515 } mSyncState;
516
517 int mProgress;
518 int mStatusFlagsJobs;
519
520 TQString mUidValidity;
521 TQString mImapPath;
522 imapState mContentState, mSubfolderState;
523 TQStringList mSubfolderNames, mSubfolderPaths,
524 mSubfolderMimeTypes, mSubfolderAttributes;
525 TQString mFolderAttributes;
526 TQString mAnnotationFolderType;
527 IncidencesFor mIncidencesFor;
528 bool mSharedSeenFlags;
529
530 bool mHasInbox;
531 bool mIsSelected;
532 bool mCheckFlags;
533 bool mReadOnly;
534 mutable TQGuardedPtr<KMAcctCachedImap> mAccount;
535
536 TQIntDict<int> uidsOnServer;
537 TQValueList<ulong> uidsForDeletionOnServer;
538 TQValueList<KMail::CachedImapJob::MsgForDownload> mMsgsForDownload;
539 TQValueList<ulong> mUidsForDownload;
540 TQStringList foldersForDeletionOnServer;
541
542 TQValueList< TQGuardedPtr<KMFolderCachedImap> > mSubfoldersForSync;
543 KMFolderCachedImap* mCurrentSubfolder;
544
548 TQMap<ulong,int> uidMap;
549 bool uidMapDirty;
550 void reloadUidMap();
551 int uidWriteTimer;
552
562 ulong mLastUid;
567 ulong mTentativeHighestUid;
568
572 bool mFoundAnIMAPDigest;
573
574 int mUserRights, mOldUserRights;
575 KMail::ACLJobs::ACLFetchState mUserRightsState;
576 ACLList mACLList;
577 KMail::ACLJobs::ACLFetchState mACLListState;
578
579 bool mSilentUpload;
580 bool mFolderRemoved;
581 //bool mHoldSyncs;
582 bool mRecurse;
583 bool mQuotaOnly;
584
586 bool mAnnotationFolderTypeChanged;
588 bool mIncidencesForChanged;
590 bool mSharedSeenFlagsChanged;
591
598 std::set<ulong> mUIDsOfLocallyChangedStatuses;
599
604 bool mStatusChangedLocally;
605
606 TQStringList mNamespacesToList;
607 int mNamespacesToCheck;
608 bool mPersonalNamespacesCheckDone;
609 TQString mImapPathCreation;
610
611 QuotaInfo mQuotaInfo;
612
615 bool mSomeSubFolderCloseToQuotaChanged;
616
617 TQMap<ulong,void*> mDeletedUIDsSinceLastSync;
618 bool mAlarmsBlocked;
619
620 TQValueList<KMFolder*> mToBeDeletedAfterRescue;
621 int mRescueCommandCount;
622
623 TQValueList< TQGuardedPtr<KMFolderCachedImap> > mNewlyCreatedSubfolders;
624 int mPermanentFlags;
625};
626
627#endif /*kmfoldercachedimap_h*/
virtual void removeMsg(int i, bool imapQuiet=false)
Remove (first occurrence of) given message from the folder.
virtual int addMsg(TQPtrList< KMMessage > &, TQValueList< int > &index_return)
Adds the given messages to the folder.
KMail list that manages the contents of one directory that may contain folders and/or other directori...
Definition: kmfolderdir.h:16
Mail folder.
Definition: kmfolder.h:69
This is a Mime Message.
Definition: kmmessage.h:68
folderdiaquotatab.h
Definition: aboutdata.cpp:40