summaryrefslogtreecommitdiffstats
path: root/kshowmail/showrecord.h
blob: 87fda3f61138af12990cce76359d59d10eb6b009 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/***************************************************************************
                          showrecord.h  -  description
                             -------------------
    begin                : Mon Dec 3 2001
    copyright            : (C) 2001 by Eggert Ehmke
    email                : eggert.ehmke@berlin.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef SHOWRECORD_H
#define SHOWRECORD_H

//C++ header
#include <iostream>

//TQt headers
#include <ntqdom.h>
#include <ntqptrlist.h>

//KDE headers
#include <kstandarddirs.h>
#include <kdebug.h>

//KShowmail headers
#include "kshowmailview.h"
#include "showrecordelem.h"
#include "types.h"
#include "headerfilter.h"
#include "filterlog.h"

using namespace Types;
using namespace std;

//forward class declarations
class ShowRecordElem;
class KshowmailView;

/**
 * @short List which contains all mails of an account.
 *
 * The mails are objects of ShowRecordElem.
 * Inherits TQPtrList.
 *
 * @see ShowRecordElem
 * @author Eggert Ehmke
 * @author Ulrich Weigelt
 */
class ShowRecord: public TQPtrList<ShowRecordElem>
{

  public:

    /**
     * Returned by showSelectedHeaders() if the user has
     * always clicked OK.
     */
    static const int continueShowHeaders;

    /**
     * Returned by showSelectedHeaders() if the user has
     * clicked Cancel.
     */
    static const int cancelShowHeaders;

    /**
     * Constructor
     */
    ShowRecord();

    /**
     * Destructor
     * Does nothing.
     */
    ~ShowRecord();

    /**
     * Saves all stored mails into the given DOM document inside the
     * given account element.
     * @param doc DOM document in that all options are stored
     * @param parent account element
     */
    void saveOptions( TQDomDocument& doc, TQDomElement& parent );

    /**
     * Reads out all mails stored inside the given account element,
     * creates objects from class ShowRecordElem and stores them in
     * this list. All old items will be removed.
     * @param parent account element (DOM element)
     */
    void readStoredMails( TQDomElement& parent );

    /**
     * Apply the filters to the mails in this list.
     * @param filter pointer to the header filter
     * @param account name of this account
     * @param deleteList reference to a list in which this methode writes the numbers of mails to delete
     * @param downloadList reference to a list in which this methode writes the number of mails to download
     * @param nmbIgnoredMails reference to an integer in which it writes the number of ignored mails
     * @param log pointer to the filter log
     */
    void applyHeaderFilter( HeaderFilter* filter, TQString account, MailNumberList_Type& deleteList, MailToDownloadMap_Type& downloadList, int& nmbIgnoredMails, FilterLog* log = NULL );


    /**
     * Returns whether there are mails in this list which are selected
     * in the list view.
     * @return TRUE - there are selected mails
     * @return FALSE - there aren't selected mails
     */
    bool hasSelectedMails();

    /**
     * Returns the numbers of all selected mails.
     * @return numbers of selected mails.
     */
    Types::MailNumberList_Type getSelectedMails();

    /**
     * Removes the mail which has the given number.
     * @param number number of the mail which will be removed
     */
    void removeMail( int number );

    /**
     * Returns the subjects of the selected mails.
     * @return subjects of selected mails
     */
    TQStringList getSelectedSubjects() const;

    /**
     * Returns the sender of the mail with the given number.
     * @param number mail number
     * @return sender
     */
    TQString getSenderOf( int number ) const;

    /**
     * Returns the date of sent of the mail with the given number.
     * @param number mail number
     * @return date
     */
    TQString getDateOf( int number ) const;

    /**
     * Returns the size of the mail with the given number.
     * @param number mail number
     * @return size
     */
    TQString getSizeOf( int number ) const;

    /**
     * Returns the subject of the mail with the given number.
     * @param number mail number
     * @return subject
     */
    TQString getSubjectOf( int number ) const;

    /**
     * Decodes the given mail body by the appropriate mail object.
     * The mail object (ShowRecordElem) has to do this job, because
     * it has stored the mail header and therefore it knows the content
     * type and encoding of the mail.
     * It decodes just the text or html part of the body. The rest of it
     * will be rejected.
     * @param body the encoded mail (including header)
     * @param number number of the downloaded mail
     * @param preferHTML decode HTML part if present
     * @return decoded mail body
     */
    TQString decodeMailBody( TQByteArray body, int number, bool preferHTML ) const;

    /**
     * Returns whether there is mail with the given uid in the list.
     * @param uid UID of the mail
     * @return TRUE - mail is in the list
     * @return FALSE - mail is not in the list
     */
    bool hasMail( TQString uid );

    /**
     * Returns whether the given mail is new.
     * @param uid UID of the mail
     * @return TRUE - mail is new
     * @return FALSE - mail is not new or mail doesn't exist
     */
    bool isNew( TQString uid ) const;

    /**
     * Appends a new mail to the list.
     * @param number number of the mail on the server
     * @param uid Unique ID of the mail
     * @param isNew TRUE - mail is new; FALSE - mail is not new
     */
    void appendNewMail( int number, TQString uid, bool isNew );

    /**
     * Just for debugging.
     * Prints a list of all contained mails to stdout.
     */
    void printMailList();

    /**
     * Sets the size of a mail.
     * @param number number of the mail
     * @param size mail size
     */
    void setSize( int number, long size );

    /**
     * Returns the numbers of mails which are marked as new.
     * @return numbers of the new mails
     */
    Types::MailNumberList_Type getNewMails();

    /**
     * Sets the header of the given mail.
     * @param number number of the mail
     * @param header the header
     */
    void setHeader( int number, TQString header );

    /**
     * Returns a list of the UIDs of all old mails.
     * @return UIDs of all old mails
     */
    TQStringList getUIDsOfOldMails();

    /**
     * Returns the header of the mail with the given UID.
     * @param uid UID
     * @return mail header
     */
    TQString getHeaderOf( TQString uid );

    /**
     * Sets the header of the mail with the given UID.
     * @param uid UID
     * @param header mail header
     */
    void setHeader( TQString uid, TQString header );

    /**
     * Returns the number of new mails.
     * @return number of new mails
     */
    int getNumberNewMails();

    /**
     * Returns the number of mails.
     * @return number of mails
     */
    int getNumberMails();

    /**
     * Returns the total size of all mails.
     * @return total size
     */
    long getTotalSize();

    /**
     * Creates for every mail a list view item and insert it
     * into the mail list view.
     * @param view pointer to the application view
     * @param account account name
     */
    void fillMailListView( KshowmailView* view, TQString& account );

    /**
     * Shows the headers of all selected mails.
     * @param account account name
     * @return continueShowHeaders - the user has always clicked OK. The invoking function will show the next header
     * @return cancelShowHeaders - the user has clicked Cancel. The invoking function will not show the next header.
     */
    int showSelectedHeaders( TQString& account );

    /**
     * Writes the mail into the Move Log.
     * @param log pointer to the log
     * @param number number of the mail
     * @param account name of the account
     * @param mailbox name of the mailbox
     */
    void writeToMoveLog( FilterLog* log, int number, TQString account, TQString mailbox );

    /**
     * Writes the mail into the Delete Log.
     * @param log pointer to the log
     * @param number number of the mail
     * @param account name of the account
     */
    void writeToDeleteLog( FilterLog* log, int number, TQString account );

    /**
     * The given mail will be marked at the next view refresh.
     * @param number number of the mail
     */
    void setMarkAtNextViewRefresh( int number );

    /**
     * Returns the senders of the selected mails
     * @return senders of the selected mails
     */
    TQStringList getSelectedSenders() const;
};

#endif