~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to kmail/popaccount.h

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- c++ -*-
2
 
#ifndef POPACCOUNT_H
3
 
#define POPACCOUNT_H
4
 
 
5
 
#include "networkaccount.h"
6
 
 
7
 
#include <QTimer>
8
 
#include <QSet>
9
 
#include <QQueue>
10
 
 
11
 
class KMPopFilterCnfrmDlg;
12
 
class KMPopHeaders;
13
 
class KMMessage;
14
 
 
15
 
class QDataStream;
16
 
class QByteArray;
17
 
class KJob;
18
 
namespace KIO {
19
 
  class MetaData;
20
 
  class Slave;
21
 
  class SimpleJob;
22
 
  class Job;
23
 
}
24
 
 
25
 
/** The namespace where all classes of KMail can be found in. */
26
 
namespace KMail {
27
 
/**
28
 
 * KMail account for pop mail account
29
 
 */
30
 
class PopAccount: public NetworkAccount {
31
 
  Q_OBJECT
32
 
 
33
 
public:
34
 
  virtual ~PopAccount();
35
 
  virtual void init(void);
36
 
 
37
 
  virtual KIO::MetaData slaveConfig() const;
38
 
 
39
 
  /**
40
 
   * Reimplemented from KMAccount
41
 
   */
42
 
  virtual void cancelMailCheck();
43
 
 
44
 
  /** A weak assignment operator */
45
 
  virtual void pseudoAssign( const KMAccount * a );
46
 
 
47
 
  virtual QString protocol() const;
48
 
  virtual unsigned short int defaultPort() const;
49
 
 
50
 
  /**
51
 
   * Sending of several commands at once
52
 
   */
53
 
  bool usePipelining(void) const { return mUsePipelining; }
54
 
  virtual void setUsePipelining(bool);
55
 
 
56
 
  /**
57
 
   * Shall messages be left on the server upon retreival (true)
58
 
   * or deleted (false).
59
 
   */
60
 
  bool leaveOnServer(void) const { return mLeaveOnServer; }
61
 
  virtual void setLeaveOnServer(bool);
62
 
 
63
 
  /**
64
 
   * If value is positive, leave mail on the server for so many days.
65
 
   */
66
 
  int leaveOnServerDays(void) const { return mLeaveOnServerDays; }
67
 
  virtual void setLeaveOnServerDays(int);
68
 
 
69
 
  /**
70
 
   * If value is positive, leave so many messages on the server.
71
 
   */
72
 
  int leaveOnServerCount(void) const { return mLeaveOnServerCount; }
73
 
  virtual void setLeaveOnServerCount(int);
74
 
 
75
 
  /**
76
 
   * If value is positive, leave so many MBs on the server.
77
 
   */
78
 
  int leaveOnServerSize(void) const { return mLeaveOnServerSize; }
79
 
  virtual void setLeaveOnServerSize(int);
80
 
 
81
 
  /**
82
 
   * Shall messages be filter on the server (true)
83
 
   * or not (false).
84
 
   */
85
 
  bool filterOnServer(void) const { return mFilterOnServer; }
86
 
  virtual void setFilterOnServer(bool);
87
 
 
88
 
  /**
89
 
   * Size of messages which should be check on the
90
 
   * pop server before download
91
 
   */
92
 
  unsigned int filterOnServerCheckSize(void) const { return mFilterOnServerCheckSize; }
93
 
  virtual void setFilterOnServerCheckSize(unsigned int);
94
 
 
95
 
  /**
96
 
   * Inherited methods.
97
 
   */
98
 
  virtual void readConfig(KConfigGroup&);
99
 
  virtual void writeConfig(KConfigGroup&);
100
 
  virtual void processNewMail(bool _interactive);
101
 
 
102
 
  virtual void killAllJobs( bool disconnectSlave=false ); // NOOP currently
103
 
 
104
 
private:
105
 
  enum Stage { Idle, List, Uidl, Head, Retr, Dele, Quit };
106
 
  friend class ::AccountManager;
107
 
  PopAccount(AccountManager* owner, const QString& accountName, uint id);
108
 
 
109
 
  /**
110
 
   * Start a KIO Job to get a list of messages on the pop server
111
 
   */
112
 
  void startJob();
113
 
 
114
 
  /**
115
 
   * Connect up the standard signals/slots for the KIO Jobs
116
 
   */
117
 
  void connectJob();
118
 
 
119
 
  /**
120
 
   * Process any queued messages
121
 
   */
122
 
  void processRemainingQueuedMessages();
123
 
 
124
 
  /**
125
 
   * Save the list of seen uids for this user/server
126
 
   */
127
 
  void saveUidList();
128
 
 
129
 
  bool    mUsePipelining;
130
 
  bool    mLeaveOnServer;
131
 
  int     mLeaveOnServerDays;
132
 
  int     mLeaveOnServerCount;
133
 
  int     mLeaveOnServerSize;
134
 
  bool    gotMsgs;
135
 
  bool    mFilterOnServer;
136
 
  unsigned int mFilterOnServerCheckSize;
137
 
 
138
 
  KIO::SimpleJob *job;
139
 
  // Map of ID's vs. sizes of messages which should be downloaded; use QMap because the order needs to be
140
 
  // predictable
141
 
  QMap<QByteArray, int> mMsgsPendingDownload;
142
 
 
143
 
  KMPopFilterCnfrmDlg *mPopFilterConfirmationDialog;
144
 
  QList<KMPopHeaders *> mHeadersOnServer;
145
 
  int mHeaderIndex;
146
 
  bool headers;
147
 
 
148
 
  QSet<QByteArray> mHeaderDeleteUids;
149
 
  QSet<QByteArray> mHeaderDownUids;
150
 
  QSet<QByteArray> mHeaderLaterUids;
151
 
 
152
 
  QList<QByteArray> idsOfMsgs; //used for ids and for count
153
 
  QHash<QByteArray, QByteArray> mUidForIdMap; // maps message ID (i.e. index on the server) to UID
154
 
  QHash<QByteArray, int> mUidsOfSeenMsgsDict; // set of UIDs of previously seen messages (for fast lookup)
155
 
  QHash<QByteArray, int> mUidsOfNextSeenMsgsDict; // set of UIDs of seen messages (for the next check)
156
 
  QVector<int> mTimeOfSeenMsgsVector; // list of times of previously seen messages
157
 
  QHash<QByteArray, int> mTimeOfNextSeenMsgsMap; // map of uid to times of seen messages
158
 
  QHash<QByteArray, int> mSizeOfNextSeenMsgsDict;
159
 
  QSet<QByteArray> idsOfMsgsToDelete;
160
 
 
161
 
  // All IDs that we'll delete in any case, even if we have "leave on server"
162
 
  // checked. This is only used when the server issues an invalid UIDL response
163
 
  // and we can't map a UID to the ID. See bug 127696.
164
 
  QSet<QByteArray> idsOfForcedDeletes; 
165
 
 
166
 
  int indexOfCurrentMsg;
167
 
 
168
 
  QQueue<KMMessage*> msgsAwaitingProcessing;
169
 
  QQueue<QByteArray> msgIdsAwaitingProcessing;
170
 
  QQueue<QByteArray> msgUidsAwaitingProcessing;
171
 
 
172
 
  QByteArray curMsgData;
173
 
  QDataStream *curMsgStrm;
174
 
 
175
 
  int curMsgLen;
176
 
  Stage stage;
177
 
  QTimer processMsgsTimer;
178
 
  int processingDelay;
179
 
  int numMsgs, numBytes, numBytesToRead, numBytesRead, numMsgBytesRead;
180
 
  bool interactive;
181
 
  bool mProcessing;
182
 
  bool mUidlFinished;
183
 
  int dataCounter;
184
 
 
185
 
protected slots:
186
 
  /**
187
 
   * Messages are downloaded in the background and then once every x seconds
188
 
   * a batch of messages are processed. Messages are processed in batches to
189
 
   * reduce flicker (multiple refreshes of the qlistview of messages headers
190
 
   * in a single second causes flicker) when using a fast pop server such as
191
 
   * one on a lan.
192
 
   *
193
 
   * Processing a message means applying KMAccount::processNewMsg to it and
194
 
   * adding its UID to the list of seen UIDs
195
 
   */
196
 
  void slotProcessPendingMsgs();
197
 
 
198
 
  /**
199
 
   * If there are more messages to be downloaded then start a new kio job
200
 
   * to get the message whose id is at the head of the queue
201
 
   */
202
 
  void slotGetNextMsg();
203
 
 
204
 
  /**
205
 
   * A messages has been retrieved successfully. The next data belongs to the
206
 
   * next message.
207
 
   */
208
 
  void slotMsgRetrieved(KJob*, const QString &, const QString &);
209
 
 
210
 
  /**
211
 
   * New data has arrived append it to the end of the current message
212
 
   */
213
 
  void slotData( KIO::Job*, const QByteArray &);
214
 
 
215
 
  /**
216
 
   * Finished downloading the current kio job, either due to an error
217
 
   * or because the job has been canceled or because the complete message
218
 
   * has been downloaded
219
 
   */
220
 
  void slotResult( KJob* );
221
 
 
222
 
  /**
223
 
   * Cleans up after a user cancels the current job
224
 
   */
225
 
  void slotCancel();
226
 
 
227
 
  /**
228
 
   * Kills the job if still stage == List
229
 
   */
230
 
  void slotAbortRequested();
231
 
 
232
 
  /**
233
 
   * Called when a job is finished. Basically a finite state machine for
234
 
   * cycling through the Idle, List, Uidl, Retr, Quit stages
235
 
   */
236
 
  void slotJobFinished();
237
 
 
238
 
  /**
239
 
   * Slave error handling
240
 
   */
241
 
  void slotSlaveError(KIO::Slave *, int, const QString &);
242
 
 
243
 
  /**
244
 
   * If there are more headers to be downloaded then start a new kio job
245
 
   * to get the next header
246
 
   */
247
 
  void slotGetNextHdr();
248
 
};
249
 
 
250
 
} // namespace KMail
251
 
 
252
 
#endif // POPACCOUNT_H