kmail

popaccount.h
00001 // -*- c++ -*-
00002 #ifndef KMAcctExpPop_h
00003 #define KMAcctExpPop_h
00004 
00005 #include "networkaccount.h"
00006 
00007 #include <tqvaluelist.h>
00008 #include <tqstringlist.h>
00009 #include <tqvaluevector.h>
00010 #include <tqtimer.h>
00011 #include <tqdict.h>
00012 
00013 class KMPopHeaders;
00014 class KMMessage;
00015 class TQDataStream;
00016 namespace KIO {
00017   class MetaData;
00018   class Slave;
00019   class SimpleJob;
00020   class Job;
00021 }
00022 
00024 namespace KMail {
00028 class PopAccount: public NetworkAccount {
00029   Q_OBJECT
00030   TQ_OBJECT
00031 
00032 public:
00033   virtual ~PopAccount();
00034   virtual void init(void);
00035 
00036   virtual KIO::MetaData slaveConfig() const;
00037 
00039   virtual void pseudoAssign( const KMAccount * a );
00040 
00041   virtual TQString protocol() const;
00042   virtual unsigned short int defaultPort() const;
00043 
00047   bool usePipelining(void) const { return mUsePipelining; }
00048   virtual void setUsePipelining(bool);
00049  
00054   bool leaveOnServer(void) const { return mLeaveOnServer; }
00055   virtual void setLeaveOnServer(bool);
00056 
00060   int leaveOnServerDays(void) const { return mLeaveOnServerDays; }
00061   virtual void setLeaveOnServerDays(int);
00062 
00066   int leaveOnServerCount(void) const { return mLeaveOnServerCount; }
00067   virtual void setLeaveOnServerCount(int);
00068 
00072   int leaveOnServerSize(void) const { return mLeaveOnServerSize; }
00073   virtual void setLeaveOnServerSize(int);
00074 
00079   bool filterOnServer(void) const { return mFilterOnServer; }
00080   virtual void setFilterOnServer(bool);
00081 
00086   unsigned int filterOnServerCheckSize(void) const { return mFilterOnServerCheckSize; }
00087   virtual void setFilterOnServerCheckSize(unsigned int);
00088 
00092   virtual TQString type(void) const;
00093   virtual void readConfig(KConfig&);
00094   virtual void writeConfig(KConfig&);
00095   virtual void processNewMail(bool _interactive);
00096 
00097   virtual void killAllJobs( bool disconnectSlave=false ); // NOOP currently
00098 
00099 protected:
00100   enum Stage { Idle, List, Uidl, Head, Retr, Dele, Quit };
00101   friend class ::AccountManager;
00102   PopAccount(AccountManager* owner, const TQString& accountName, uint id);
00103 
00107   void startJob();
00108 
00112   void connectJob();
00113 
00117   void processRemainingQueuedMessages();
00118 
00122   void saveUidList();
00123 
00124   bool    mUsePipelining;
00125   bool    mLeaveOnServer;
00126   int     mLeaveOnServerDays;
00127   int     mLeaveOnServerCount;
00128   int     mLeaveOnServerSize;
00129   bool    gotMsgs;
00130   bool    mFilterOnServer;
00131   unsigned int mFilterOnServerCheckSize;
00132 
00133   KIO::SimpleJob *job;
00134   //Map of ID's vs. sizes of messages which should be downloaded
00135   TQMap<TQString, int> mMsgsPendingDownload;
00136 
00137   TQPtrList<KMPopHeaders> headersOnServer;
00138   TQPtrListIterator<KMPopHeaders> headerIt;
00139   bool headers;
00140 
00141   TQMap<TQString, bool> mHeaderDeleteUids;
00142   TQMap<TQString, bool> mHeaderDownUids;
00143   TQMap<TQString, bool> mHeaderLaterUids;
00144 
00145   TQStringList idsOfMsgs; //used for ids and for count
00146   TQValueList<int> lensOfMsgs;
00147   TQMap<TQString, TQString> mUidForIdMap; // maps message ID (i.e. index on the server) to UID
00148   TQDict<int> mUidsOfSeenMsgsDict; // set of UIDs of previously seen messages (for fast lookup)
00149   TQDict<int> mUidsOfNextSeenMsgsDict; // set of UIDs of seen messages (for the next check)
00150   TQValueVector<int> mTimeOfSeenMsgsVector; // list of times of previously seen messages
00151   TQMap<TQString, int> mTimeOfNextSeenMsgsMap; // map of uid to times of seen messages
00152   TQDict<int> mSizeOfNextSeenMsgsDict;
00153   TQStringList idsOfMsgsToDelete;
00154   TQStringList idsOfForcedDeletes;
00155   int indexOfCurrentMsg;
00156 
00157   TQValueList<KMMessage*> msgsAwaitingProcessing;
00158   TQStringList msgIdsAwaitingProcessing;
00159   TQStringList msgUidsAwaitingProcessing;
00160 
00161   TQByteArray curMsgData;
00162   TQDataStream *curMsgStrm;
00163 
00164   int curMsgLen;
00165   Stage stage;
00166   TQTimer processMsgsTimer;
00167   int processingDelay;
00168   int numMsgs, numBytes, numBytesToRead, numBytesRead, numMsgBytesRead;
00169   bool interactive;
00170   bool mProcessing;
00171   bool mUidlFinished;
00172   int dataCounter;
00173 
00174 protected slots:
00185   void slotProcessPendingMsgs();
00186 
00191   void slotGetNextMsg();
00192 
00197   void slotMsgRetrieved(KIO::Job*, const TQString &);
00198 
00202   void slotData( KIO::Job*, const TQByteArray &);
00203 
00209   void slotResult( KIO::Job* );
00210 
00214   void slotCancel();
00215 
00219   void slotAbortRequested();
00220 
00225   void slotJobFinished();
00226 
00230   void slotSlaveError(KIO::Slave *, int, const TQString &);
00231 
00236   void slotGetNextHdr();
00237 };
00238 
00239 } // namespace KMail
00240 
00241 
00242 
00243 #endif /*KMAcctExpPop_h*/