summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/statusmail.cpp83
-rw-r--r--noncore/net/mail/libmailwrapper/statusmail.h31
2 files changed, 114 insertions, 0 deletions
diff --git a/noncore/net/mail/libmailwrapper/statusmail.cpp b/noncore/net/mail/libmailwrapper/statusmail.cpp
new file mode 100644
index 0000000..3e1d8d1
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/statusmail.cpp
@@ -0,0 +1,83 @@
+#include "statusmail.h"
+#include "mailtypes.h"
+#include "abstractmail.h"
+#include <qlist.h>
+
+StatusMail::StatusMail(QList<Account>*list)
+{
+ currentImapStat.message_count=0;
+ currentImapStat.message_unseen=0;
+ currentImapStat.message_recent=0;
+ lastPop3Stat = currentImapStat;
+ currentPop3Stat = currentImapStat;
+ connectionList.setAutoDelete(true);
+ connectionList.clear();
+ initAccounts(list);
+}
+
+StatusMail::~StatusMail()
+{
+}
+
+void StatusMail::initAccounts(QList<Account>*accounts)
+{
+ if (!accounts) return;
+ Account *it;
+ folderStat currentStat;
+ AbstractMail * current = 0;
+ for ( it = accounts->first(); it; it = accounts->next() ) {
+ if ( it->getType().compare( "IMAP" ) == 0 ) {
+ IMAPaccount*ima = static_cast<IMAPaccount *>(it);
+ current = AbstractMail::getWrapper(ima);
+ connectionList.append(current);
+ current->statusFolder(currentStat);
+ currentImapStat.message_count+=currentStat.message_unseen;
+ currentImapStat.message_count+=currentStat.message_recent;
+ currentImapStat.message_count+=currentStat.message_count;
+ } else if ( it->getType().compare( "POP3" ) == 0 ) {
+ POP3account *pop3 = static_cast<POP3account *>(it);
+ current = AbstractMail::getWrapper(pop3);
+ connectionList.append(current);
+ current->statusFolder(currentStat);
+ currentPop3Stat.message_count+=currentStat.message_unseen;
+ currentPop3Stat.message_count+=currentStat.message_recent;
+ currentPop3Stat.message_count+=currentStat.message_count;
+ }
+ current->logout();
+ }
+ lastPop3Stat = currentPop3Stat;
+}
+
+void StatusMail::reset_status()
+{
+ lastPop3Stat = currentPop3Stat;
+}
+
+void StatusMail::check_current_stat(folderStat&targetStat)
+{
+ AbstractMail*it = 0;
+ folderStat currentStat;
+ currentPop3Stat.message_recent = 0;
+ currentPop3Stat.message_count = 0;
+ currentPop3Stat.message_unseen = 0;
+ currentImapStat = currentPop3Stat;
+ for ( it = connectionList.first(); it; it = connectionList.next() ) {
+ it->statusFolder(currentStat);
+ it->logout();
+ if (it->getType().lower()=="imap") {
+ currentImapStat.message_unseen+=currentStat.message_unseen;
+ currentImapStat.message_recent+=currentStat.message_recent;
+ currentImapStat.message_count+=currentStat.message_count;
+ } else if (it->getType().lower()=="pop3") {
+ currentPop3Stat.message_count+=currentStat.message_count;
+ }
+ }
+ if (currentPop3Stat.message_count > lastPop3Stat.message_count) {
+ currentPop3Stat.message_recent = currentPop3Stat.message_count - lastPop3Stat.message_count;
+ currentPop3Stat.message_unseen = currentPop3Stat.message_recent;
+ }
+ targetStat = currentImapStat;
+ targetStat.message_unseen+=currentPop3Stat.message_unseen;
+ targetStat.message_recent+=currentPop3Stat.message_recent;
+ targetStat.message_count+=currentPop3Stat.message_count;
+}
diff --git a/noncore/net/mail/libmailwrapper/statusmail.h b/noncore/net/mail/libmailwrapper/statusmail.h
new file mode 100644
index 0000000..498f7a3
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/statusmail.h
@@ -0,0 +1,31 @@
+#ifndef __MAIL_STATUS_H
+#define __MAIL_STATUS_H
+
+#include <settings.h>
+#include <abstractmail.h>
+#include <mailtypes.h>
+
+class StatusMail
+{
+public:
+ StatusMail(QList<Account>*list);
+ virtual ~StatusMail();
+
+ /* this should be called if opiemail is starte or a mailbox touched - may be trough
+ a qcop signal or if tab on the taskbar applet*/
+ virtual void reset_status();
+ virtual void check_current_stat(folderStat&targetStat);
+
+protected:
+ void initAccounts(QList<Account>*list);
+ /* this must be cause we have to calculate the recent for pop3*/
+ folderStat currentImapStat;
+ /* currentPop3Stat is the sum of messages in POP3 accounts in CURRENT loop
+ the recent are calculated to the difference of the LAST loop */
+ folderStat currentPop3Stat;
+ /* lastPop3Stat is the sum of messages in LAST loop */
+ folderStat lastPop3Stat;
+ QList<AbstractMail> connectionList;
+};
+
+#endif