TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

popaccount.h 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. // -*- c++ -*-
  2. #ifndef KMAcctExpPop_h
  3. #define KMAcctExpPop_h
  4. #include "networkaccount.h"
  5. #include <tqvaluelist.h>
  6. #include <tqstringlist.h>
  7. #include <tqvaluevector.h>
  8. #include <tqtimer.h>
  9. #include <tqdict.h>
  10. class KMPopHeaders;
  11. class KMMessage;
  12. class TQDataStream;
  13. namespace TDEIO {
  14. class MetaData;
  15. class Slave;
  16. class SimpleJob;
  17. class Job;
  18. }
  19. /** The namespace where all classes of KMail can be found in. */
  20. namespace KMail {
  21. /**
  22. * KMail account for pop mail account
  23. */
  24. class PopAccount: public NetworkAccount {
  25. Q_OBJECT
  26. public:
  27. virtual ~PopAccount();
  28. virtual void init(void);
  29. virtual TDEIO::MetaData slaveConfig() const;
  30. /** A weak assignment operator */
  31. virtual void pseudoAssign( const KMAccount * a );
  32. virtual TQString protocol() const;
  33. virtual unsigned short int defaultPort() const;
  34. /**
  35. * Sending of several commands at once
  36. */
  37. bool usePipelining(void) const { return mUsePipelining; }
  38. virtual void setUsePipelining(bool);
  39. /**
  40. * Shall messages be left on the server upon retreival (TRUE)
  41. * or deleted (FALSE).
  42. */
  43. bool leaveOnServer(void) const { return mLeaveOnServer; }
  44. virtual void setLeaveOnServer(bool);
  45. /**
  46. * If value is positive, leave mail on the server for so many days.
  47. */
  48. int leaveOnServerDays(void) const { return mLeaveOnServerDays; }
  49. virtual void setLeaveOnServerDays(int);
  50. /**
  51. * If value is positive, leave so many messages on the server.
  52. */
  53. int leaveOnServerCount(void) const { return mLeaveOnServerCount; }
  54. virtual void setLeaveOnServerCount(int);
  55. /**
  56. * If value is positive, leave so many MBs on the server.
  57. */
  58. int leaveOnServerSize(void) const { return mLeaveOnServerSize; }
  59. virtual void setLeaveOnServerSize(int);
  60. /**
  61. * Shall messages be filter on the server (TRUE)
  62. * or not (FALSE).
  63. */
  64. bool filterOnServer(void) const { return mFilterOnServer; }
  65. virtual void setFilterOnServer(bool);
  66. /**
  67. * Size of messages which should be check on the
  68. * pop server before download
  69. */
  70. unsigned int filterOnServerCheckSize(void) const { return mFilterOnServerCheckSize; }
  71. virtual void setFilterOnServerCheckSize(unsigned int);
  72. /**
  73. * Inherited methods.
  74. */
  75. virtual TQString type(void) const;
  76. virtual void readConfig(TDEConfig&);
  77. virtual void writeConfig(TDEConfig&);
  78. virtual void processNewMail(bool _interactive);
  79. virtual void killAllJobs( bool disconnectSlave=false ); // NOOP currently
  80. protected:
  81. enum Stage { Idle, List, Uidl, Head, Retr, Dele, Quit };
  82. friend class ::AccountManager;
  83. PopAccount(AccountManager* owner, const TQString& accountName, uint id);
  84. /**
  85. * Start a TDEIO Job to get a list of messages on the pop server
  86. */
  87. void startJob();
  88. /**
  89. * Connect up the standard signals/slots for the TDEIO Jobs
  90. */
  91. void connectJob();
  92. /**
  93. * Process any queued messages
  94. */
  95. void processRemainingQueuedMessages();
  96. /**
  97. * Save the list of seen uids for this user/server
  98. */
  99. void saveUidList();
  100. bool mUsePipelining;
  101. bool mLeaveOnServer;
  102. int mLeaveOnServerDays;
  103. int mLeaveOnServerCount;
  104. int mLeaveOnServerSize;
  105. bool gotMsgs;
  106. bool mFilterOnServer;
  107. unsigned int mFilterOnServerCheckSize;
  108. TDEIO::SimpleJob *job;
  109. //Map of ID's vs. sizes of messages which should be downloaded
  110. TQMap<TQString, int> mMsgsPendingDownload;
  111. TQPtrList<KMPopHeaders> headersOnServer;
  112. TQPtrListIterator<KMPopHeaders> headerIt;
  113. bool headers;
  114. TQMap<TQString, bool> mHeaderDeleteUids;
  115. TQMap<TQString, bool> mHeaderDownUids;
  116. TQMap<TQString, bool> mHeaderLaterUids;
  117. TQStringList idsOfMsgs; //used for ids and for count
  118. TQValueList<int> lensOfMsgs;
  119. TQMap<TQString, TQString> mUidForIdMap; // maps message ID (i.e. index on the server) to UID
  120. TQDict<int> mUidsOfSeenMsgsDict; // set of UIDs of previously seen messages (for fast lookup)
  121. TQDict<int> mUidsOfNextSeenMsgsDict; // set of UIDs of seen messages (for the next check)
  122. TQValueVector<int> mTimeOfSeenMsgsVector; // list of times of previously seen messages
  123. TQMap<TQString, int> mTimeOfNextSeenMsgsMap; // map of uid to times of seen messages
  124. TQDict<int> mSizeOfNextSeenMsgsDict;
  125. TQStringList idsOfMsgsToDelete;
  126. TQStringList idsOfForcedDeletes;
  127. int indexOfCurrentMsg;
  128. TQValueList<KMMessage*> msgsAwaitingProcessing;
  129. TQStringList msgIdsAwaitingProcessing;
  130. TQStringList msgUidsAwaitingProcessing;
  131. TQByteArray curMsgData;
  132. TQDataStream *curMsgStrm;
  133. int curMsgLen;
  134. Stage stage;
  135. TQTimer processMsgsTimer;
  136. int processingDelay;
  137. int numMsgs, numBytes, numBytesToRead, numBytesRead, numMsgBytesRead;
  138. bool interactive;
  139. bool mProcessing;
  140. bool mUidlFinished;
  141. int dataCounter;
  142. protected slots:
  143. /**
  144. * Messages are downloaded in the background and then once every x seconds
  145. * a batch of messages are processed. Messages are processed in batches to
  146. * reduce flicker (multiple refreshes of the qlistview of messages headers
  147. * in a single second causes flicker) when using a fast pop server such as
  148. * one on a lan.
  149. *
  150. * Processing a message means applying KMAccount::processNewMsg to it and
  151. * adding its UID to the list of seen UIDs
  152. */
  153. void slotProcessPendingMsgs();
  154. /**
  155. * If there are more messages to be downloaded then start a new tdeio job
  156. * to get the message whose id is at the head of the queue
  157. */
  158. void slotGetNextMsg();
  159. /**
  160. * A messages has been retrieved successfully. The next data belongs to the
  161. * next message.
  162. */
  163. void slotMsgRetrieved(TDEIO::Job*, const TQString &);
  164. /**
  165. * New data has arrived append it to the end of the current message
  166. */
  167. void slotData( TDEIO::Job*, const TQByteArray &);
  168. /**
  169. * Finished downloading the current tdeio job, either due to an error
  170. * or because the job has been canceled or because the complete message
  171. * has been downloaded
  172. */
  173. void slotResult( TDEIO::Job* );
  174. /**
  175. * Cleans up after a user cancels the current job
  176. */
  177. void slotCancel();
  178. /**
  179. * Kills the job if still stage == List
  180. */
  181. void slotAbortRequested();
  182. /**
  183. * Called when a job is finished. Basically a finite state machine for
  184. * cycling through the Idle, List, Uidl, Retr, Quit stages
  185. */
  186. void slotJobFinished();
  187. /**
  188. * Slave error handling
  189. */
  190. void slotSlaveError(TDEIO::Slave *, int, const TQString &);
  191. /**
  192. * If there are more headers to be downloaded then start a new tdeio job
  193. * to get the next header
  194. */
  195. void slotGetNextHdr();
  196. };
  197. } // namespace KMail
  198. #endif /*KMAcctExpPop_h*/