Diffstat (limited to 'kmicromail/libmailwrapper/statusmail.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/statusmail.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/kmicromail/libmailwrapper/statusmail.cpp b/kmicromail/libmailwrapper/statusmail.cpp new file mode 100644 index 0000000..90c9233 --- a/dev/null +++ b/kmicromail/libmailwrapper/statusmail.cpp | |||
@@ -0,0 +1,94 @@ | |||
1 | #include "statusmail.h" | ||
2 | |||
3 | |||
4 | |||
5 | using namespace Opie::Core; | ||
6 | |||
7 | StatusMail::StatusMail(QList<Account>&list) | ||
8 | { | ||
9 | currentImapStat.message_count=0; | ||
10 | currentImapStat.message_unseen=0; | ||
11 | currentImapStat.message_recent=0; | ||
12 | lastPop3Stat = currentImapStat; | ||
13 | currentPop3Stat = currentImapStat; | ||
14 | connectionList.setAutoDelete(true); | ||
15 | connectionList.clear(); | ||
16 | initAccounts(list); | ||
17 | } | ||
18 | |||
19 | StatusMail::~StatusMail() | ||
20 | { | ||
21 | } | ||
22 | |||
23 | void StatusMail::initAccounts(QList<Account>&accounts) | ||
24 | { | ||
25 | |||
26 | Account *it; | ||
27 | folderStat currentStat; | ||
28 | AbstractMail * current = 0; | ||
29 | currentPop3Stat.message_count=0; | ||
30 | currentPop3Stat.message_recent=0; | ||
31 | currentPop3Stat.message_unseen=0; | ||
32 | for ( it = accounts.first(); it; it = accounts.next() ) { | ||
33 | if ( it->getType()==MAILLIB::A_IMAP && !it->getOffline() ) { | ||
34 | IMAPaccount*ima = static_cast<IMAPaccount *>(it); | ||
35 | current = AbstractMail::getWrapper(ima); | ||
36 | connectionList.append(current); | ||
37 | current->statusFolder(currentStat); | ||
38 | currentImapStat.message_count+=currentStat.message_unseen; | ||
39 | currentImapStat.message_count+=currentStat.message_recent; | ||
40 | currentImapStat.message_count+=currentStat.message_count; | ||
41 | } else if ( it->getType() == MAILLIB::A_POP3 && !it->getOffline() ) { | ||
42 | POP3account *pop3 = static_cast<POP3account *>(it); | ||
43 | current = AbstractMail::getWrapper(pop3); | ||
44 | connectionList.append(current); | ||
45 | current->statusFolder(currentStat); | ||
46 | currentPop3Stat.message_count+=currentStat.message_count; | ||
47 | } | ||
48 | current->logout(); | ||
49 | } | ||
50 | ; // << "Pop3 init count: " << currentPop3Stat.message_count << "" << oendl; | ||
51 | currentPop3Stat.message_recent = currentPop3Stat.message_unseen = 0; | ||
52 | lastPop3Stat.message_unseen = currentPop3Stat.message_unseen; | ||
53 | lastPop3Stat.message_recent = currentPop3Stat.message_recent; | ||
54 | lastPop3Stat.message_count = currentPop3Stat.message_count; | ||
55 | } | ||
56 | |||
57 | void StatusMail::reset_status() | ||
58 | { | ||
59 | lastPop3Stat = currentPop3Stat; | ||
60 | } | ||
61 | |||
62 | void StatusMail::check_current_stat(folderStat&targetStat) | ||
63 | { | ||
64 | AbstractMail*it = 0; | ||
65 | folderStat currentStat; | ||
66 | currentPop3Stat.message_recent = 0; | ||
67 | currentPop3Stat.message_count = 0; | ||
68 | currentPop3Stat.message_unseen = 0; | ||
69 | currentImapStat = currentPop3Stat; | ||
70 | for ( it = connectionList.first(); it; it = connectionList.next() ) { | ||
71 | it->statusFolder(currentStat); | ||
72 | it->logout(); | ||
73 | if (it->getType() == MAILLIB::A_IMAP) { | ||
74 | currentImapStat.message_unseen+=currentStat.message_unseen; | ||
75 | currentImapStat.message_recent+=currentStat.message_recent; | ||
76 | currentImapStat.message_count+=currentStat.message_count; | ||
77 | } else if (it->getType() == MAILLIB::A_POP3) { | ||
78 | currentPop3Stat.message_count+=currentStat.message_count; | ||
79 | ; // << "Pop3 count: " << currentPop3Stat.message_count << "" << oendl; | ||
80 | } | ||
81 | } | ||
82 | ; // << "Pop3 last: " << lastPop3Stat.message_count << "" << oendl; | ||
83 | if (currentPop3Stat.message_count > lastPop3Stat.message_count) { | ||
84 | currentPop3Stat.message_recent = currentPop3Stat.message_count - lastPop3Stat.message_count; | ||
85 | currentPop3Stat.message_unseen = currentPop3Stat.message_recent; | ||
86 | } else { | ||
87 | lastPop3Stat.message_count = currentPop3Stat.message_count; | ||
88 | currentPop3Stat.message_recent = currentPop3Stat.message_unseen = 0; | ||
89 | } | ||
90 | targetStat = currentImapStat; | ||
91 | targetStat.message_unseen+=currentPop3Stat.message_unseen; | ||
92 | targetStat.message_recent+=currentPop3Stat.message_recent; | ||
93 | targetStat.message_count+=currentPop3Stat.message_count; | ||
94 | } | ||