kmail

imapaccountbase.h
1/*
2 * imapaccountbase.h
3 *
4 * Copyright (c) 2000-2002 Michael Haeckel <haeckel@kde.org>
5 * Copyright (c) 2002 Marc Mutz <mutz@kde.org>
6 *
7 * This file is based on work on pop3 and imap account implementations
8 * by Don Sanders <sanders@kde.org> and Michael Haeckel <haeckel@kde.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2 of the License
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 */
23
24#ifndef __KMAIL_IMAPACCOUNTBASE_H__
25#define __KMAIL_IMAPACCOUNTBASE_H__
26
27#include <set>
28
29#include "networkaccount.h"
30
31#include <tqtimer.h>
32#include <tqguardedptr.h>
33#include <tdeio/global.h>
34
35namespace KMail {
36 class AccountManager;
37}
38class KMFolder;
39class TDEConfig/*Base*/;
40class KMMessagePart;
41class DwBodyPart;
42class DwMessage;
43class FolderStorage;
44template <typename T> class TQValueVector;
45
46namespace TDEIO {
47 class Job;
48}
49
50namespace KPIM {
51 class ProgressItem;
52}
53
54namespace KMail {
55 struct ACLListEntry;
56 struct QuotaInfo;
57 typedef TQValueVector<KMail::ACLListEntry> ACLList;
58
59 class AttachmentStrategy;
60
61 class ImapAccountBase : public KMail::NetworkAccount {
62 TQ_OBJECT
63
64 protected:
65 ImapAccountBase( AccountManager * parent, const TQString & name, uint id );
66 public:
67 virtual ~ImapAccountBase();
68
70 virtual void init();
71
73 virtual void pseudoAssign( const KMAccount * a );
74
77 bool autoExpunge() const { return mAutoExpunge; }
78 virtual void setAutoExpunge( bool expunge );
79
81 bool hiddenFolders() const { return mHiddenFolders; }
82 virtual void setHiddenFolders( bool show );
83
85 bool onlySubscribedFolders() const { return mOnlySubscribedFolders; }
86 virtual void setOnlySubscribedFolders( bool show );
87
89 bool onlyLocallySubscribedFolders() const { return mOnlyLocallySubscribedFolders; }
90 virtual void setOnlyLocallySubscribedFolders( bool show );
91
92
94 bool loadOnDemand() const { return mLoadOnDemand; }
95 virtual void setLoadOnDemand( bool load );
96
98 bool listOnlyOpenFolders() const { return mListOnlyOpenFolders; }
99 virtual void setListOnlyOpenFolders( bool only );
100
102 virtual TDEIO::MetaData slaveConfig() const;
103
104 virtual void readConfig( TDEConfig& config );
105 virtual void writeConfig( TDEConfig& config );
106
110 enum ConnectionState { Error = 0, Connected, Connecting };
111
112 // possible list types
113 enum ListType {
114 List,
115 ListSubscribed,
116 ListSubscribedNoCheck,
117 ListFolderOnly,
118 ListFolderOnlySubscribed
119 };
120
127 ConnectionState makeConnection();
128
129 // namespace defines
130 enum imapNamespace { PersonalNS=0, OtherUsersNS=1, SharedNS=2 };
131
132 // map a namespace type to a list of namespaces
133 typedef TQMap<imapNamespace, TQStringList> nsMap;
134
135 // map a namespace to a delimiter
136 typedef TQMap<TQString, TQString> namespaceDelim;
137
138 // map a namespace type to a map with the namespace and the delimiter
139 typedef TQMap<imapNamespace, namespaceDelim> nsDelimMap;
140
144 struct jobData
145 {
146 // Needed by TQMap, don't use
147 jobData() : url(TQString()), parent(0), current(0), total(1), done(0), offset(0), progressItem(0),
148 onlySubscribed(false), quiet(false), cancellable(false) {}
149 // Real constructor
150 jobData( const TQString& _url, KMFolder *_parent = 0,
151 int _total = 1, int _done = 0, bool _quiet = false,
152 bool _cancelable = false )
153 : url(_url), parent(_parent), current(0), total(_total), done(_done), offset(0),
154 progressItem(0), quiet(_quiet), cancellable(_cancelable) {}
155
156 TQString path;
157 TQString url;
158 TQString curNamespace;
159 TQByteArray data;
160 TQCString cdata;
161 TQStringList items;
162 KMFolder *parent, *current;
163 TQPtrList<KMMessage> msgList;
164 int total, done, offset;
165 KPIM::ProgressItem *progressItem;
166 bool onlySubscribed, quiet, cancellable;
167 };
168
169 typedef TQMap<TDEIO::Job *, jobData>::Iterator JobIterator;
173 void insertJob( TDEIO::Job* job, const jobData& data ) {
174 mapJobData.insert( job, data );
175 }
179 JobIterator findJob( TDEIO::Job* job ) { return mapJobData.find( job ); }
180 JobIterator jobsEnd() { return mapJobData.end(); }
185 void removeJob( JobIterator& it );
186
187 void removeJob( TDEIO::Job* job );
188
196 void changeSubscription(bool subscribe, const TQString& imapPath, bool quiet = false );
197
202 bool locallySubscribedTo( const TQString& imapPath );
203
208 void changeLocalSubscription( const TQString& imapPath, bool subscribe );
209
210
216 void getUserRights( KMFolder* folder, const TQString& imapPath );
217
223 void getACL( KMFolder* folder, const TQString& imapPath );
224
230 void getStorageQuotaInfo( KMFolder* folder, const TQString& imapPath );
231
236 void setImapStatus( KMFolder* folder, const TQString& path, const TQCString& flags );
237
242 void setImapSeenStatus( KMFolder* folder, const TQString& path, bool seen );
243
247 void slaveDied() { mSlave = 0; killAllJobs(); }
248
252 void killAllJobs( bool disconnectSlave=false ) = 0;
253
257 virtual void cancelMailCheck();
258
262 enum FolderListType { Single, Recursive };
263 void processNewMailInFolder( KMFolder* folder, FolderListType type = Single );
264
268 bool checkingSingleFolder() { return mCheckingSingleFolder; }
269
274 void postProcessNewMail( bool setStatusMsg = true );
275
280 bool checkingMail( KMFolder *folder );
281
282 bool checkingMail() { return NetworkAccount::checkingMail(); }
283
287 void handleBodyStructure( TQDataStream & stream, KMMessage * msg,
288 const AttachmentStrategy *as );
289
293 virtual void setFolder(KMFolder*, bool addAccount = false);
294
299 bool hasACLSupport() const { return mACLSupport; }
300
305 bool hasAnnotationSupport() const { return mAnnotationSupport; }
306
310 void setHasNoAnnotationSupport() { mAnnotationSupport = false; }
311
316 bool hasQuotaSupport() const { return mQuotaSupport; }
317
321 void setHasNoQuotaSupport() { mQuotaSupport = false; }
322
327 bool handleJobError( TDEIO::Job* job, const TQString& context, bool abortSync = false );
328
332 virtual FolderStorage* rootFolder() const = 0;
333
337 KPIM::ProgressItem* listDirProgressItem();
338
343 virtual unsigned int folderCount() const;
344
348 nsMap namespaces() const { return mNamespaces; }
349
353 virtual void setNamespaces( nsMap map )
354 { mNamespaces = map; }
355
360 nsDelimMap namespacesWithDelimiter();
361
365 TQString namespaceForFolder( FolderStorage* );
366
370 TQString addPathToNamespace( const TQString& ns );
371
375 TQString delimiterForNamespace( const TQString& prefix );
376
380 TQString delimiterForFolder( FolderStorage* );
381
385 namespaceDelim namespaceToDelimiter() const
386 { return mNamespaceToDelimiter; }
387
391 void setNamespaceToDelimiter( namespaceDelim map )
392 { mNamespaceToDelimiter = map; }
393
397 bool isNamespaceFolder( TQString& name );
398
402 bool hasCapability( const TQString& capa ) {
403 return mCapabilities.contains( capa ); }
404
410 TQString createImapPath( FolderStorage* parent, const TQString& folderName );
411
415 TQString createImapPath( const TQString& parent, const TQString& folderName );
416
417
418 public slots:
423 void getNamespaces();
424
425 private slots:
430 void slotSubscriptionResult(TDEIO::Job * job);
431
432 protected slots:
433 virtual void slotCheckQueuedFolders();
434
436 void slotSchedulerSlaveConnected(TDEIO::Slave *aSlave);
438 void slotSchedulerSlaveError(TDEIO::Slave *aSlave, int, const TQString &errorMsg);
439
443 void slotSetStatusResult(TDEIO::Job * job);
444
446 void slotGetUserRightsResult( TDEIO::Job* _job );
447
449 void slotGetACLResult( TDEIO::Job* _job );
450
452 void slotGetStorageQuotaInfoResult( TDEIO::Job* _job );
453
457 void slotNoopTimeout();
461 void slotIdleTimeout();
462
466 void slotAbortRequested( KPIM::ProgressItem* );
467
471 void slotSimpleResult(TDEIO::Job * job);
472
474 void slotNamespaceResult( TDEIO::Job*, const TQString& str );
475
479 void slotSaveNamespaces( const ImapAccountBase::nsDelimMap& map );
480
484 void slotCapabilitiesResult( TDEIO::Job*, const TQString& result );
485
486 protected:
487
504 virtual bool handleError( int error, const TQString &errorMsg, TDEIO::Job* job, const TQString& context, bool abortSync = false );
505
507 bool handlePutError( TDEIO::Job* job, jobData& jd, KMFolder* folder );
508
509 virtual TQString protocol() const;
510 virtual unsigned short int defaultPort() const;
511
515 void constructParts( TQDataStream & stream, int count, KMMessagePart* parentKMPart,
516 DwBodyPart * parent, const DwMessage * dwmsg );
517
519 void migratePrefix();
520
521 // used for writing the blacklist out to the config file
522 TQStringList locallyBlacklistedFolders() const;
523 void localBlacklistFromStringList( const TQStringList & );
524 TQString prettifyQuotaError( const TQString& _error, TDEIO::Job * job );
525
526 protected:
527 TQPtrList<TQGuardedPtr<KMFolder> > mOpenFolders;
528 TQStringList mSubfolderNames, mSubfolderPaths,
529 mSubfolderMimeTypes, mSubfolderAttributes;
530 TQMap<TDEIO::Job *, jobData> mapJobData;
532 TQTimer mIdleTimer;
534 TQTimer mNoopTimer;
535 int mTotal, mCountUnread, mCountLastUnread;
536 TQMap<TQString, int> mUnreadBeforeCheck;
537 bool mAutoExpunge : 1;
538 bool mHiddenFolders : 1;
539 bool mOnlySubscribedFolders : 1;
540 bool mOnlyLocallySubscribedFolders : 1;
541 bool mLoadOnDemand : 1;
542 bool mListOnlyOpenFolders : 1;
543 bool mProgressEnabled : 1;
544
545 bool mErrorDialogIsActive : 1;
546 bool mPasswordDialogIsActive : 1;
547 bool mACLSupport : 1;
548 bool mAnnotationSupport : 1;
549 bool mQuotaSupport : 1;
550 bool mSlaveConnected : 1;
551 bool mSlaveConnectionError : 1;
552 bool mCheckingSingleFolder : 1;
553
554 // folders that should be checked for new mails
555 TQValueList<TQGuardedPtr<KMFolder> > mMailCheckFolders;
556 // folders that should be checked after the current check is done
557 TQValueList<TQGuardedPtr<KMFolder> > mFoldersQueuedForChecking;
558 // holds messageparts from the bodystructure
559 TQPtrList<KMMessagePart> mBodyPartList;
560 // the current message for the bodystructure
561 KMMessage* mCurrentMsg;
562
563 TQGuardedPtr<KPIM::ProgressItem> mListDirProgressItem;
564
565 // our namespaces in the form section=namespaceList
566 nsMap mNamespaces;
567
568 // namespace - delimiter map
569 namespaceDelim mNamespaceToDelimiter;
570
571 // old prefix for migration
572 TQString mOldPrefix;
573
574 // capabilities
575 TQStringList mCapabilities;
576
577 std::set<TQString> mLocalSubscriptionBlackList;
578
579 signals:
586 void connectionResult( int errorCode, const TQString& errorMsg );
587
592 void subscriptionChanged(const TQString& imapPath, bool subscribed);
593
598 void subscriptionChangeFailed( const TQString &errorMessage );
599
605 void imapStatusChanged( KMFolder*, const TQString& imapPath, bool cont );
606
613 void receivedUserRights( KMFolder* folder );
614
622 void receivedACL( KMFolder* folder, TDEIO::Job* job, const KMail::ACLList& entries );
623
632 void receivedStorageQuotaInfo( KMFolder* folder, TDEIO::Job* job, const KMail::QuotaInfo& entries );
633
637 void namespacesFetched( const ImapAccountBase::nsDelimMap& );
638
642 void namespacesFetched();
643 };
644
645
646} // namespace KMail
647
648#endif // __KMAIL_IMAPACCOUNTBASE_H__
The FolderStorage class is the bass class for the storage related aspects of a collection of mail (a ...
Definition: folderstorage.h:80
Mail folder.
Definition: kmfolder.h:69
int find(const KMMsgBase *msg) const
Returns the index of the given message or -1 if not found.
Definition: kmfolder.cpp:435
This is a Mime Message.
Definition: kmmessage.h:68
The account manager is responsible for creating accounts of various types via the factory method crea...
GetUserRightsJob * getUserRights(TDEIO::Slave *slave, const KURL &url)
Get the users' rights for a given url.
Definition: acljobs.cpp:158
GetACLJob * getACL(TDEIO::Slave *slave, const KURL &url)
List all ACLs for a given url.
Definition: acljobs.cpp:147
folderdiaquotatab.h
Definition: aboutdata.cpp:40