summaryrefslogtreecommitdiffstats
path: root/kshowmail/showrecordelem.h
blob: e14ef3f33c1aa5a5405232b533a3dacbfb79ff28 (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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
/***************************************************************************
                          showrecord.h  -  description
                             -------------------
    begin                : Thu Dec 28 2000
    copyright            : (C) 2000-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 SHOWRECORDELEM_H
#define SHOWRECORDELEM_H

//TQt headers
#include <ntqdom.h>
#include <ntqstring.h>
#include <ntqlistview.h>
#include <ntqdatetime.h>

//KDE headers
#include <tdelocale.h>
#include <tdeglobal.h>
#include <kdebug.h>
#include <mimelib/datetime.h>
#include <kmdcodec.h>

//KShowmail headers
#include "showlistviewitem.h"
#include "decodeRFC2047.h"
#include "constants.h"
#include "kshowmailview.h"
#include "showheaderdialog.h"
#include "headerfilter.h"
#include "filterlog.h"

using namespace Constants;

//forward class declarations
class KshowmailView;
class FilterElem;

/**
 * @short Represents a mail.
 *
 * It contains UID, Subject, From, To and date of the mail. Subject, From and To
 * will be read out from the given header. It also contains pointer to the
 * corresponding list view entry and maybe to a matching filter.
 * All mail objects are held by ShowRecord.
 * @see ShowRecord
 * @see ConfigElem
 * @author Eggert Ehmke
 */

class ShowRecordElem
{

  public:

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

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

    /**
     * Constructor
     */
	ShowRecordElem ();

    /**
     * Constructor
     * @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
     */
    ShowRecordElem( int number, TQString& uid, bool isNew );

    /**
     * Sets the mail header and extracts From, To, Subject, Date and Content Type.
     * All parts of the header are coded according RFC 2047.
     * @param header the mail header
     */
    void setHeader( const TQString& header );

    /**
     * Returns the whole header.
     * @return the mail header
     */
    TQString header() const;

    /**
     * Returns the sender address.
     * @return sender address
     */
    TQString from() const;

    /**
     * Returns the addressee.
     * @return the addressee
     */
    TQString to() const;

    /**
     * Returns the subject.
     * @return mail subject
     */
    TQString subject() const;

    /**
     * Returns the stored content type.
     * @return content type
     */
    TQString content() const;


    /**
     * Returns the date on which the mail was sent, formated to the current
     * locale's conventions.
     * @return the date
     */
    TQString date() const;

    /**
     * Returns the date on which the mail was sent.
     * The format corresponds to the ISO 8601 extended specification for
     * representations of dates and times, which is YYYY-MM-DDTHH:MM:SS
     * @return the date
     */
    TQString strUnixTime () const;

    /**
     * Returns the date and time on which the mail was sent.
     * @return the date
     */
    TQDateTime sentDateTime() const;

    /**
     * Sets the unique mail ID.
     * @param uid the ID
     */
    void setUIDL( const TQString& uid );

    /**
     * Returns the unique ID of this mail.
     * @return UID
     */
    TQString uidl() const;

    /**
     * Sets the size of the mail.
     * @param size Size
     */
    void setSize( int size );

    /**
     * Returns the mail size as numeric value.
     * @return size of the mail
     */
    int size() const;

    /**
     * Returns the mail size as string.
     * The String has a length of 8 and the number is right-aligned to allow sorting.
     */
    TQString strSize () const;

    /**
     * Returns the mails size as string with prefix
     */
    TQString strSizePrefix() const;

    /**
     * Sets whether the mail is new or not.
     * @param isnew TRUE - mail is new; FALSE - mail is not new
     */
    void setNew( bool isnew );

    /**
     * Returns whether the mail is new or not.
     * @return TRUE - mail is new
     * @return FALSE - mail is not new
     */
    bool isNew() const;

    /**
     * Returns whether the mail is new or not.
     * @return localized String "new", if the mail is new
     * @return localized String "old", if the mail is not new
     */
    TQString state() const;

    /**
     * Sets the number of this mail.
     * @param n mail number
     */
    void setNumber( int n );

    /**
     * Returns the number of this mail.
     * @return mail number
     */
    int number() const;

    /**
     * Sets the pointer to the corresponding list view item.
     * @see m_pItem
     * @see ShowListViewItem
     * @param item pointer to the corresponding item
     */
    void setViewItem( ShowListViewItem* item );

    /**
     * Returns the pointer to the corresponding list view item.
     * @see m_pItem
     * @see ShowListViewItem
     * @return pointer to the item
     */
    ShowListViewItem* viewItem() const;

    /**
     * Looks for a filter matching the mail header and returns the action recommend by this filter.
     * If the action is MARK, it set markAtViewRefresh to True so the related view entry will be marked
     * at the next view refresh.
     * @param filter pointer to the header filter
     * @param account name of the account
     * @param mailbox reference to a TQString object in which the mailbox name shall be written if the action is MOVE
     * @param log pointer to the filter log
     * @return recommend action
     * @see FilterAction_Type
     * @see HeaderFilter
     * @see markAtViewRefresh
     */
    FilterAction_Type applyHeaderFilter( HeaderFilter* filter, TQString account, TQString& mailbox, FilterLog* log = NULL );

    /**
     * Read a mail (header, size, uid and number) from the given DOM element
     * and store it in this mail object.
     * The element has to contains the attributes "uidl", "size", "number" and
     * a child node called "header".
     * @param elem a DOM element which contains a mail
     */
    void readOptions( TQDomElement& elem );

    /**
     * Creates a new DOM element in the given DOM document and add it to given
     * DOM parent element
     * @param doc the DOM document in that all options are stored
     * @param parent the parent element (account) of the mail
     */
    void saveOptions( TQDomDocument& doc, TQDomElement& parent );

    /**
     * Returns whether the mail is selected in the list view.
     * @return TRUE - mail is selected
     * @return FALSE - mail is not selected
     */
    bool isSelected() const;

    /**
     * Decodes the given mail body.
     * The mail object 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 preferHTML decode HTML part if present
     * @return decoded mail body
     */
    TQString decodeMailBody( TQByteArray body, bool preferHTML ) const;

    /**
     * Shows the header in a dialog box.
     * @param account account name
     * @return continueShowHeaders - the user has OK clicked. The invoking function will show the next header
     * @return cancelShowHeaders - the user has Cancel clicked. The invoking function will not show the next header.
     */
    int showHeader( TQString& account );

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

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

    /**
     * The mail will be marked at the next view refresh.
     */
    void setMarkAtNextViewRefresh();

  private:

    /**
     * Mail header; coded according RFC 2047
     */
    TQCString m_header;

    /**
     * The sender address; coded according RFC 2047
     */
    TQCString m_from;

    /**
     * The addressee; coded according RFC 2047
     */
    TQCString m_to;

    /**
     * The subject; coded according RFC 2047
     */
    TQCString m_subject;

    /**
     * The date on which the mail was sent
     */
    TQDateTime m_unixDate;

    /**
     * The content type
     */
    TQCString m_content;

    /**
     * The unique ID of the mail.
     */
    TQString m_uid;

    /**
     * Size of the mail
     */
    int m_size;

    /**
     * It is set to TRUE when the mail is new.
     */
    bool m_new;

    /**
     * The mail number of the account
     */
    int m_nNumber;

    /**
     * TRUE - the mail shall be marked at the next mail view refresh.
     * It will be set to True by applyHeaderFilter() if the recommend filter action is MARK.
     * It is used by setViewItem(). This methode marks the related list entry and after then it set
     * this variable to False.
     */
    bool markAtViewRefresh;

    /**
     * Pointer to the corresponding list view entry. Used to check
     * whether the entry is highlighted and we have to process this mail.
     * @see ShowListViewItem
     */
    ShowListViewItem* m_pItem;

    /**
     * Searches in the header for a line which starts with the
     * given item.
     * For example:
     * scanHeader( "From") will find the line
     * "From: Ulrich Weigelt <ulrich.weigelt@gmx.de>"
     * and returns "Ulrich Weigelt <ulrich.weigelt@gmx.de>"
     * Returns an empty string (""), if nothing was found.
     * @param item the search item
     * @return the content of the found line
     */
    TQCString scanHeader( const TQString& item ) const;

    /**
     * Sets the given string as sender address
     * @param from sender address
     */
    void setFrom( const TQCString& from );

    /**
     * Sets the given string as recipient address
     * @param to recipient address
     */
    void setTo( const TQCString& to );

    /**
     * Sets the given string as subject
     * @param subject the mail subject
     */
    void setSubject( const TQCString& subject );

    /**
     * Converts the given string to a date-time value and stores it.
     * @param date the date
     */
    void setDate( const TQCString& date );

    /**
     * Sets the given string as content type.
     * @param content the content type
     */
    void setContent( const TQCString& content );

    /**
     * Returns the boundary, if the mail has a multi part body.
     * Otherwise it returns an empty string.
     * @return boundary
     */
    TQString getBoundary() const;

    /**
     * Returns the char set of the content (e.g. iso-8859-1).
     * If no char set is denoted, it will returns an empty string.
     * @return charset
     */
    TQString getCharset() const;

    /**
     * Returns the content transfer encoding of the content
     * (e.g. quoted-printable).
     * If no encoding is denoted, it will returns an empty string.
     * @return content transfer encoding
     */
    TQString getTransferEncoding() const;

};

#endif