summaryrefslogtreecommitdiffstats
path: root/kshowmail/configelem.h
blob: c81bca275bae45c82a876f0daee444430cc3263c (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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
/***************************************************************************
                          configelem.h  -  description
                             -------------------
    begin                : Tue May 9 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 CONFIGELEM_H
#define CONFIGELEM_H

//C headers
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

//QT headers
#include <ntqstring.h>
#include <ntqlistview.h>
#include <ntqdom.h>
#include <ntqobject.h>
#include <ntqtimer.h>
#include <ntqregexp.h>
#include <ntqdir.h>
#include <ntqfile.h>
#include <ntqtextstream.h>

//KDE headers
#include <kurl.h>
#include <tdeconfig.h>
#include <kdebug.h>
#include <kpassdlg.h>
#include <tdeio/job.h>
#include <tdeio/global.h>
#include <tdemessagebox.h>
#include <tdeapplication.h>

//KShowmail headers
#include "showrecord.h"
#include "constants.h"
#include "types.h"
#include "configlist.h"
#include "showmaildialog.h"
#include "decodeRFC2047.h"
#include "kshowmailview.h"
#include "encryption.h"
#include "tdewalletaccess.h"
#include "headerfilter.h"
#include "filterlog.h"



using namespace Constants;
using namespace Types;
using namespace Encryption;

//forward class declarations
class KshowmailView;
class ConfigList;
class ShowRecordElem;
class ShowRecord;

/**
 * @brief Represents a mail account.
 *
 * Contains all datas of the account like server, user password and so on.
 * It also contains the mails read from the server.
 * Used in class ConfigList and ConfigAccounts.
 *
 * @see ShowRecord
 * @see ConfigList
 * @see ConfigAccounts::Accounts
 * @author Eggert Ehmke <eggert.ehmke@berlin.de>
 * @author Ulrich Weigelt <ulrich.weigelt@gmx.de>
 */
class ConfigElem : public TQObject {

  Q_OBJECT

  public:

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

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

    /**
     * General Constructor
     * Warning: The pointer to the application configuration (ConfigList)
     * will not be set.
     */
    ConfigElem();

    /**
     * Default Constructor
     * @param config pointer to the general app configuration
     */
    ConfigElem ( ConfigList* config );

    /**
     * Copy Constructor.
     * It doesn't copy the mail list but creates a new empty one.
     * The pointer to the appropriate account list view item is set
     * to NULL.The new account is active by default.
     * @param pElem the account which will be copied
     */
    ConfigElem( ConfigElem* pElem );

    /**
     * Constructs a account which is called like the given name.
     * Creates a empty mail list. Sets the pointer to the appropriate
     * account list view item to NULL. The account is deactivated by default.
     * The url doesn't contain any server informations.
     * @param config pointer to the general app configuration
     * @param account name of the new account
     */
    ConfigElem( ConfigList* config, const TQString& account );

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

    /**
     * Returns whether the account is active.
     * @return TRUE - account is active; FALSE - account is not active
     */
    bool isActive() const;

    /**
     * Sets the account active.
     * @param active TRUE - active account; FALSE - deactivate account
     */
    void setActive( bool active );

   /**
    * Gets the account name.
    * @return account name
    */
   TQString getAccountName() const;

   /**
    * Sets the account name.
    * @param name the account name
    */
   void setAccountName( TQString name );

   /**
    * Gets the account password.
    * @return password
    */
   TQString getPassword() const;

   /**
    * Sets the account password. To save it in the configuration file
    * call saveOptions().
    * @param password new password
    */
   void setPassword( const TQString& password );

   /**
    * Returns whether a password is stored.
    * @return TRUE - there is password stored; FALSE - no password stored
    */
   bool hasPassword() const;

   /**
    * Returns the url of this account.
    * @return url
    */
   KURL getURL() const;

   /**
    * Sets the pointer to the item in the account list view item.
    * @see m_pViewItem
    * @param item account list view item
    */
   void setListViewItem( TQListViewItem* item );

   /**
    * Returns the pointer to the account list view item.
    * @see m_pViewItem
    * @return pointer to the appropriate list view item
    */
   TQListViewItem* getListViewItem();

   /**
    * Returns TRUE, if the appropriate list view item is selected.
    * @return TRUE - list view item is selected
    * @return FALSE - list view item is not selected
    */
   bool isSelected() const;

   /**
    * Clears the mail list or creates a new one.
    */
   void clearMailList();

   /**
    * Sets the host name.
    * @param host host name
    */
   void setHost( const TQString& host );

   /**
    * Returns the hostname.
    * @return the name of the host or TQString::null if no host is set
    */
   TQString getHost() const;

   /**
    * Sets the protocol.
    * @param protocol the protocol
    */
   void setProtocol( const TQString& protocol );

   /**
    * Returns the protocol.
    * @param upperCase TRUE - transforms the protocol string to upper case
    * @return protocol
    */
   TQString getProtocol( bool upperCase = false ) const;

   /**
    * Enable or disable TLS.
    * @param tls TRUE: use TLS; FALSE: don't use TLS
    */
   void setTLS( bool tls );

   /**
    * Returns whether TLS is enabled.
    * @return TRUE: TLS is enabled
    * @return FALSE: TLS is disabled
    */
   bool getTLS() const;

   /**
    * Sets the port.
    * @param port the port
    */
   void setPort( unsigned short int port );

   /**
    * Returns the port number.
    * @return port number
    */
   unsigned short int getPort() const;

   /**
    * Sets the user.
    * @param user username
    */
   void setUser( const TQString& user );

   /**
    * Returns the user name.
    * @return the user name or TQString::null if there is no user name
    */
   TQString getUser() const;

   /**
    * Sets the password storage type.
    * The Constants are defined in constants.h
    * @param storage type of password storage; valid values are: CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE, CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE, CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_TDEWALLET
    */
   void setPasswordStorage( int storage );

   /**
    * Returns the password storage type.
    * The Constants are defined in constants.h.
    * @return type of password storage; valid values are: CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE, CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE, CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_TDEWALLET
    */
   int getPasswordStorage() const;


  /**
   * Saves the stored mails into the given
   * DOM document. It doesn't create a new DOM element but used the given one.
   * Saves the setup into the application config.
   * @param doc DOM document which contains all application settings, mails and account settings
   * @param parent DOM element in which all settings and mails of this account will be saved
   */
  void saveOptions( TQDomDocument& doc, TQDomElement& parent );

  /**
   * Gets the stored mails.
   * @param parent DOM element which contains the mails of this account
   */
  void readStoredMails( TQDomElement& parent );

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

  /**
   * Deletes all selected mails.
   * This just starts the deletion and returns after then.
   * When the deletion is ready the signal sigDeleteReady will be emitted.
   */
  void deleteSelectedMails();

  /**
   * Downloads and shows the bodies of all selected mails.
   * This just starts the download and returns after then.
   * When the download is ready and the body is shown the sigShowBodiesReady
   * will be emitted.
   */
  void showSelectedMails();

  /**
   * Opens a dialog to ask for a password, stores it temporarily in the account settings and
   * emits the signal sigConfigChanged.
   * Does not open a dialog if a password is already stored in the account settings.
   * @param force ask for a new password even if a password is stored
   * @return TRUE - a password is available
   * @return FALSE - no password is available
   */
  bool assertPassword( bool force = false );

  /**
   * Returns the state of the account.
   * @return account state
   */
  Types::AccountState_Type getState();

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

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

  /**
   * Refreshes the mail list.
   * This just starts the refresh and returns after then.
   * When the refresh is ready, the signal sigRefreshReady
   * will be emitted.
   * @param log Pointer to the filter log
   * @see sigRefreshReady
   */
  void refreshMailList( FilterLog* log = NULL );

  /**
   * 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
   */
  void fillMailListView( KshowmailView* view );

  /**
   * Refreshes the appropriate entry of the account list
   * (number of mails and total size)
   * Uses the pointer to the list view item stored in m_pViewItem.
   */
  void refreshAccountListItem();

  /**
   * Kills a running pop3 job.
   */
  void killPOP3Job();

  /**
   * Shows the headers of all selected mails.
   * @return continueShowHeaders - the user has 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.
   * @return continueShowHeaders - no mails of this account are selected
   */
  int showSelectedHeaders();

  /**
   * Prints the setup to stdout.
   */
  void printSetup() const;

  /**
   * Reloads the settings of the filters.
   * It just calls the load() methode of the header filter.
   */
  void reloadFilterSettings();

    /**
     * Returns the number of deleted mails by last refresh.
     * @return number of deleted mails by last refresh
     */
  int numberDeletedMailsLastRefresh();

    /**
     * Returns the number of deleted mails since start.
     * @return number of deleted mails since start
     */
  int numberDeletedMailsStart();

    /**
     * Returns the number of moved mails by last refresh.
     * @return number of moved mails by last refresh
     */
  int numberMovedMailsLastRefresh();

    /**
     * Returns the number of moved mails since start.
     * @return number of moved mails since start
     */
  int numberMovedMailsStart();

    /**
     * Returns the number of ignored mails by last refresh.
     * @return number of ignored mails by last refresh
     */
  int numberIgnoredMails();

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


  private:

    /**
     * Pointer to the configuration of the application.
     * Set by the constructors.
     */
    ConfigList* appConfig;

    /**
     * Pointer to the filter log.
     * Will be set by refreshMailList() at every refresh.
     */
    FilterLog* FLog;

    /**
     * State of the account.
     */
    Types::AccountState_Type state;

    /**
     * Type of password storage.
     * valid values are: CONFIG_VALUE_ACCOUNT_PASSWORD_DONT_SAVE, CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_FILE, CONFIG_VALUE_ACCOUNT_PASSWORD_SAVE_TDEWALLET
     * The Constants are defined in constants.h
     * @see saveOptions()
     * @see setPasswordStorage()
     */
    int PasswordStorage;

    /**
     * TRUE - account is active; FALSE - account is not active
     */
    bool m_bActive;

    /**
     * Account Name
     */
    TQString m_strAccount;

    /**
     * Pointer to the appropriate item in the account list view.
     */
    TQListViewItem* m_pViewItem;

    /**
     * List which contains all read mails from the server.
     */
    ShowRecord* m_pshowrecord;

    /**
     * Uniform Resource Locator of the account on the pop3 server.
     */
    KURL m_url;

    /**
     * Type of secure login.
     * See constants.h for valid values (CONFIG_VALUE_ACCOUNT_SECLOGIN_...)
     */
    int secureLoginType;

    /**
     * False: TLS is enabled
     */
    bool useTLS;

    /**
     * Contains a downloaded mail body.
     * Will be set by slotDataMailBody() and read by slotBodyDownloaded().
     */
    TQByteArray mailbody;

   /**
    * Contains the numbers of mails which will be deleted.
    * Set by deleteSelectedMails() and applyFilters() and used by deleteNextMail() to get
    * the number of the next mail to delete.
    * @see deleteSelectedMails()
    * @see deleteNextMail()
    * @see applyFilters()
    */
    MailNumberList_Type MailsToDelete;

    /**
     * Contains the numbers of the mails shall be moved for actions like moving to mailbox or spam check.
     * Contains also some parameters (like mailbox) about the action which have to be performed.
     * Set and used by applyFilters().
     * @see applyFilters()
     */
    MailToDownloadMap_Type MailsToDownload;

    /**
     * Contains the numbers of mails for which the bodies will be shown.
     * Set by showSelectedMails() and used by showNextMail() to get
     * the number of the next mail to show.
     * @see showSelectedMails()
     * @see showNextMail()
     */
    MailNumberList_Type MailsToShow;

    /**
     * Contains the numbers of new mails.
     * Set by getHeaders() and used by getNextHeader() to download
     * the headers of the new mails.
     * @see getHeaders()
     * @see getNextHeader()
     */
    MailNumberList_Type newMails;

    /**
     * Pointer to a launched pop3 job.
     */
    TDEIO::TransferJob* pop3Job;

    /**
     * timeout timer. Will be started together with every pop3 job.
     * If it runs down, slotTimeout() will be invoked.
     */
    TQTimer* pop3Timer;

    /**
     * While refreshing, this ShowRecord instance will be used to
     * build a new mail list. After that this pointer will be assigned
     * to m_pshowrecord.
     */
    ShowRecord* tempMailList;

    /**
     * List of received mail UIDs (unique ID).
     * Used by slotReceiveUID() and slotUIDsReceived().
     */
    TQStringList receivedUIDs;

    /**
     * List of received mail sizes.
     * Used by slotReceiveSize() and slotSizesReceived().
     */
    TQStringList receivedSizes;

    /**
     * A received mail header.
     * Set by slotReceiveHeader() and used by slotHeaderDownloaded().
     */
    TQByteArray receivedHeader;

    /**
     * Every account has is own header filter instance.
     */
    HeaderFilter headerFilter;

    /**
     * This is a flag whether the filters was applied during a refresh cycle.
     * If the some mails was deleted (recommend by the filter), we need a actual
     * list of mails from the server. Therefore a second refresh cycle will be started.
     * To avoid a never-ending loop this flag will be set to TRUE by applyFilters().
     * If the second refresh is running this one will not invoke the filters.
     */
    bool filterApplied;

    /**
     * This flag is set by applyFilters() to indicate the deletion cycle is performed by filters and not by user.
     * The deletion methodes need it to decide on branch targets
     */
    bool deletionPerformedByFilters;

    /**
     * This flag is set by applyFiltersDeleted() to indicate the refresh cycle is the second one after a deletion which was performed by filters.
     * The refresh cycle need it to hold the remaining mails as new.
     */
    bool refreshPerformedByFilters;

    /**
     * This flag is set to TRUE by applyFilters() to indicate the mailbodies are downloading and writing to the mailboxes or spam checking.
     * When this is ended, applyFilters() will be called again and it reset this flag
     */
    bool downloadActionsInvoked;

    /**
     * Counter for moving to create an unique file name
     */
    int moveCounter;

    /**
     * Number of deleted mails by last refresh.
     */
    int nmbDeletedMailsLastRefresh;

    /**
     * Number of deleted mails since start.
     */
    int nmbDeletedMailsLastStart;

    /**
     * Number of moved mails by last refresh.
     */
    int nmbMovedMailsLastRefresh;

    /**
     * Number of moved mails since start.
     */
    int nmbMovedMailsLastStart;

    /**
     * Number of ignored mails by last refresh.
     */
    int nmbIgnoredMails;

    /**
     * Initializes the account.
     */
    void init();

    /**
     * Deletes the first mail of MailsToDelete.
     * After a succesful deletion this mail will be removed from the list
     * by slotMailDeleted() and this method will be invoked again.
     * If the list is empty, it will call commitDelete.
     * @see slotMailDeleted()
     * @see MailsToDelete
     */
    void deleteNextMail();

    /**
     * Commits the deletion.
     * Starts a pop3 job that will do the commit. Its signal
     * result is connected with slotFinalizeDeletion().
     * @see slotFinalizeDeletion()
     */
    void commitDeletion();

    /**
     * Shows the body of the first mail in MailsToShow.
     * After a succesful download and opening of the window this
     * mail will be removed from the list by slotBodyDownloaded() and this
     * method will be invoked again.
     * If the list is empty, it will call commitDownloading().
     * @see commitDownloading()
     * @see slotBodyDownloaded()
     */
    void showNextMail();

    /**
     * Commits the downloading of mail bodies.
     * Starts a pop3 job that will do the commit. Its signal
     * result is connected with slotFinalizeShowMail().
     * @see slotFinalizeShowMail()
     */
    void commitDownloading();

    /**
     * Creates a POP3 transfer job (TDEIO Job), which will be stored in pop3Job.
     * @param path command and parameters of the job as URL path
     */
    void startKIOJob( const TQString& path );

    /**
     * Returns the timeout time in seconds which is stored in the
     * general configuration of the application.
     * Returns POP3_DEFAULT_TIMEOUT_TIME (defined in constants.h),
     * if no time is available.
     * Returns POP3_MINIMUM_TIMEOUT_TIME (defined in constants.h),
     * if the get time is less than POP3_MINIMUM_TIMEOUT_TIME.
     * @return seconds to timeout
     */
    unsigned int getTimeoutTime();

    /**
     * First step of the refresh cycle.
     * Gets the UIDs of the available mails from the server.
     * It starts a TDEIO job to get the UIDs. The UIDs will be stored
     * in receivedUIDs by slotReceiveUID().
     * When the job is ready, it will invoke slotUIDsReceived().
     */
    void getUIDs();

    /**
     * Second step of the refresh cycle.
     * Gets the sizes of the available mails from the server.
     * It starts a TDEIO job to get these. The Sizes will be temporarily
     * stored in receivedSizes by slotReceiveSize().
     * When the job is ready, it will invoke slotSizesReceived().
     */
    void getSizes();

    /**
     * Third step of the refresh cycle.
     * Gets the header of the new mails from the server.
     */
    void getHeaders();

    /**
     * Get the header of the first mail in newMails.
     * After a succesful download this
     * mail will be removed from the list by slotHeaderDownloaded() and this
     * method will be invoked again.
     * If the list is empty, it will call copyHeaders() to get the known
     * headers from the old mail list (m_pshowrecord).
     * @see copyHeaders()
     * @see slotHeaderDownloaded()
     */
    void getNextHeader();

    /**
     * Fourth step of the refresh cycle.
     * Copies the known headers of the old mails from the
     * old mail list to the new one.
     * At the end it invokes swapMailLists().
     */
    void copyHeaders();

    /**
     * Sixth step of the refresh cycle.
     * Applies the filters to the mails in the mail list.
     * Invoked by swapMailLists().
     * This methode maybe starts a new refresh cycle because after a deletion or moving we need a
     * actual list of mails on the server.
     * To avoid a never-ending loop you must not call this methode during the second refresh cycle.
     * Therefore it sets filterApplied to TRUE.
     * @see filterApplied
     * @see applyFiltersDeleted()
     */
    void applyFilters();

    /**
     * If there are mails to delete by filters applyFilters will call the regular deletion cycle of this class with set byFilter-flag.
     * Therefore the deletion will not branch to commitDeletion() but to this methode.
     * This performs a second refresh cycle to get an effective mail list from the server.
     * This new cycle will not apply the filters again, because the flag filterApplied is set to TRUE.
     * @see applyFilters()
     * @see filterApplied
     */
    void applyFiltersDeleted();

    /**
     * Cancels the refresh. Will be invoked, when a pop3 job has
     * reported an error.
     */
    void cancelRefresh();

    /**
     * Commits the refresh.
     * Starts a pop3 job that will do the commit. Its signal
     * result is connected with slotFinalizeRefresh().
     * Invoked by copyHeaders() if the filters was applied or applyFilters()
     * if not second refresh was necessary.
     * @see slotFinalizeRefresh()
     * @see applyFilters()
     */
    void commitRefresh();

    /**
     * Send a commit and restart the refresh cycle
     * We restart the refresh to get a fresh maillist after a deletion performed by the filter.
     * We need a commit before because the mails server only after a commit reorders the mail numbers
     */
    void commitBeforeRefresh();

    /**
     * Fifth step of the refresh cycle.
     * Copies the pointer to the temporary list to m_pshowrecord.
     * Invoked by copyHeaders() and slotUIDsReceived().
     * The temporary list will be the current mail list.
     * At the end it invokes commitRefresh() if the filters were applied
     * (filterApplied == TRUE) or deactive or it invokes
     * applyFilters() if the filters were not
     * applied (filterApplied == FALSE).
     * @see m_pshowrecord
     * @see copyHeaders()
     * @see slotUIDsReceived()
     * @see commitRefresh()
     * @see filterApplied
     */
    void swapMailLists();

    /**
     * Does all filter actions for which we have to download the mails
     * These are:
     * Moving, spam check
     * It doesn't removes they from the server.
     */
    void doDownloadActions();

    /**
     * Gets the body of the first mail in MailsToDownload.
     * After a succesful download and writing into the mailbox this
     * mail will be removed from the list by slotMailDownloadedforDownloadActions() and this
     * method will be invoked again.
     * If the list is empty, it will call applyFilters() to continue the filtering.
     * @see applyFilters()
     * @see slotMailDownloadedforDownloadActions()
     */
    void getNextMailForDownloadActions();

    /**
     * Returns whether the given directory is a maildir directory
     * @param path the directory for test
     * @return TRUE - directory is a maildir directory
     */
    bool isMailDir( const TQDir& path );

    /**
     * Writes the given mail into the mailbox.
     * @param mail the Mail
     * @param box path to the mailbox
     * @return TRUE - Writing was succesful
     */
    bool writeToMailBox( const TQString& mail, const TQString& box );

  private slots:

    /**
     * Connected with signal result of the launched pop3 job.
     * Removes the deleted mail from the internal mail list (m_pshowrecord).
     * Removes the first mail from MailsToDelete and invokes
     * deleteNextMail() again to delete the next mail.
     * If the list is empty after it has removed the first item, it will call
     * commitDelete().
     * If an error is occured, it will call slotFinalizeDeletion().
     * @param job job which has emit the result signal
     * @see deleteNextMail()
     * @see MailsToDelete
     * @see pop3Job
     * @see slotFinalizeDeletion()
     */
    void slotMailDeleted( TDEIO::Job* job );

    /**
     * Connected with the signal result of the job which commits the deletion.
     * Finalizes the deletion of mails.
     * Emits signal sigDeleteReady.
     * @see deleteNextMail()
     * @see slotMailDeleted()
     * @see sigDeleteReady
     */
    void slotFinalizeDeletion( TDEIO::Job* );

    /**
     * Connected with signal result of the launched pop3 job to
     * download a mail body.
     * Opens a window (class ShowMailDialog) with the downloaded mail body.
     * Removes the first mail from MailsToShow and invokes showNextMail()
     * again to show the next mail.
     * If the list is empty after it has removed the first item, it will call
     * commitDownloading().
     * If an error is occured, it will call slotFinalizeShowMail().
     * @param job job which has emit the result signal
     * @see showNextMail()
     * @see commitDownloading()
     * @see MailsToShow
     * @see pop3Job
     * @see slotFinalizeShowMail()
     * @see ShowMailDialog
     */
    void slotBodyDownloaded( TDEIO::Job* job );

    /**
     * Connected with signal result of the launched pop3 job to
     * download a mail to write it into a mailbox or do a spam check.
     * Maybe it puts the number of the downloaded mail into the list of mails to delete (MailsToDelete).
     * Removes the first mail from MailsToMove and invokes getNextMailForMove()
     * again to get and write the next mail.
     * If the list is empty after it has removed the first item, it will call
     * applyFilters() to continue the filtering.
     * If an error is occured the current mail will not put into MailsToDelete. And it returns
     * to applyFilters() immediately.
     * @param job job which has emit the result signal
     * @see MailsToDownload
     * @see getNextMailForDownloadActions()
     * @see applyFilters()
     */
    void slotMailDownloadedForAction( TDEIO::Job* job );

    /**
     * Connected with signal data of the launched pop3 job to
     * download a mail body.
     * Receives the downloaded data from the job. This lot will be called
     * several times during the donwload. At the last one the array is empty.
     * It extracts the body from the downloaded data and stores it in DownloadedMailBody.
     * @param datas the downloaded mail
     */
    void slotDataMailBody( TDEIO::Job*, const TQByteArray & datas );

    /**
     * Connected with the signal result of the job which commits the download
     * of the mail bodies.
     * Finalizes the downloading and showing of the selected mails.
     * Emits signal sigShowBodiesReady and sets account state to idle.
     * @see showNextMail()
     * @see slotBodyDownloaded()
     * @see sigShowBodiesReady
     */
    void slotFinalizeShowMail( TDEIO::Job* );

    /**
     * Connected with signal timeout() of the timeout timer pop3Timer.
     * Will be called when the timer is run down, if the pop3 job
     * has not ended on time.
     * It kills a running pop3 job and invokes the appropriate finalize slot
     * of the running operation.
     */
    void slotTimeout();

    /**
     * Connected with the signal "data" of the pop3 transfer job which gets mail
     * UIDs (Unique ID). Therefore it will be called when the job has received
     * an UIDL from the server. Every received UID causes a call of this slot.
     * When the job ends, it causes a last call but with an empty data array.
     * The UIDs will be stored in receivedUIDs.
     * @param data received data, which contain an uid
     */
    void slotReceiveUID( TDEIO::Job*, const TQByteArray& data );

    /**
     * Connected with signal result of the launched pop3 job to get the UIDs.
     * Will be invoked, when all UIDs are received and stored in receivedUIDs.
     * Analyzes the received UID datas and creates new ShowRecordElem instances
     * in the new mail list accordingly.
     * @param job job which has emitted the result signal
     */
    void slotUIDsReceived( TDEIO::Job* job );

    /**
     * Connected with the signal "data" of the pop3 transfer job which gets mail
     * Sizes. Therefore it will be called when the job has received
     * a size from the server. Every received size causes a call of this slot.
     * When the job ends, it causes a last call but with an empty data array.
     * The UIDs will be stored in receivedSizes.
     * @param data received data, which contain a size
     */
    void slotReceiveSize( TDEIO::Job*, const TQByteArray& data );

    /**
     * Connected with signal result of the launched pop3 job to get the Sizes.
     * Will be invoked, when all Sizes are received and stored in receivedSizes.
     * Analyzes the received datas and writes these in the appropriate mail instances.
     * @param job job which has emitted the result signal
     */
    void slotSizesReceived( TDEIO::Job* job );


    /**
     * Connected with signal result of the job which commits the refresh.
     * Finalizes a succesful refresh.
     * Emits sigRefreshReady and sets account state to idle
     */
    void slotFinalizeRefresh( TDEIO::Job* );

    /**
     * Connected with signal result of the launched pop3 job.
     * Stores the received headers into the appropriate instance of the mail list.
     * Removes the first mail from newMails and invokes
     * getNextHeader() again to get the next header.
     * If the list is empty after it has removed the first item, it will call
     * copyHeaders().
     * If an error has occured, it will call cancelRefresh().
     * @param job job which has emit the result signal
     * @see getNextHeader()
     * @see newMails
     * @see pop3Job
     * @see cancelRefresh()
     * @see copyHeaders()
     */
    void slotHeaderDownloaded( TDEIO::Job* job );

    /**
     * Connected with the signal "data" of the pop3 transfer job which gets a mail
     * header. Therefore it will be called when the job has received
     * a part of the header from the server.
     * When the job ends, it causes a last call but with an empty data array.
     * The complete header will be stored in receivedHeader.
     * @param data received data, which contains a header part
     */
    void slotReceiveHeader( TDEIO::Job*, const TQByteArray& data );
    
    /**
     * Connected with the result signal of the pop3 job launched by commitBeforeRefresh()
     * Restarts a second refresh cycle after a deletion performed by the filter.
     * @see commitBeforeRefresh
     * @see applyFiltersDeleted
     */
    void slotCommitBeforeRefreshDone( TDEIO::Job* );


  signals:

    /**
     * Will be emitted when all selected mails are deleted.
     * @param account name of the account, which has emitted this signal
     */
    void sigDeleteReady( TQString account );

    /**
     * Will be emitted when the bodies of all selected mails are
     * downloaded and shown.
     * @param account name of the account, which has emitted this signal
     */
    void sigShowBodiesReady( TQString account );

    /**
     * Will be emitted when the settings have been changed.
     */
    void sigConfigChanged();

    /**
     * Will be emitted, when a window to show a message was opened.
     */
    void sigMessageWindowOpened();

    /**
     * Will be emitted, when a window to show a message was closed.
     */
    void sigMessageWindowClosed();

    /**
     * Will be emitted, when the mail list was refreshed.
     * @param account name of the account, which has emitted this signal
     */
    void sigRefreshReady( TQString account );

  protected:

    /**
     * Forwards the given mail to SpamAssassin and returns the test result
     * @param mail the mail to test
     * @return TRUE - mail is spam
     */
    bool isSpam( TQByteArray mail ) const;

    /**
     * Looks for a running spamd daemon of SpamAssassin.
     * @return TRUE - SpamAssassin is running
     */
    bool isSpamAssassinRunning() const;



};
#endif