summaryrefslogtreecommitdiffstats
path: root/libmail/smapnewmail.C
diff options
context:
space:
mode:
authorSam Varshavchik2013-08-19 16:39:41 -0400
committerSam Varshavchik2013-08-25 14:43:51 -0400
commit9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch)
tree7a81a04cb51efb078ee350859a64be2ebc6b8813 /libmail/smapnewmail.C
parenta9520698b770168d1f33d6301463bb70a19655ec (diff)
downloadcourier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2
Initial checkin
Imported from subversion report, converted to git. Updated all paths in scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'libmail/smapnewmail.C')
-rw-r--r--libmail/smapnewmail.C110
1 files changed, 110 insertions, 0 deletions
diff --git a/libmail/smapnewmail.C b/libmail/smapnewmail.C
new file mode 100644
index 0000000..490c0a7
--- /dev/null
+++ b/libmail/smapnewmail.C
@@ -0,0 +1,110 @@
+/*
+** Copyright 2003, Double Precision Inc.
+**
+** See COPYING for distribution information.
+*/
+
+#include "smap.H"
+#include "imapfolder.H"
+#include "smapopen.H"
+#include "smapnewmail.H"
+#include <string.h>
+#include <sstream>
+
+using namespace std;
+
+const char *mail::smapNEWMAIL::getName()
+{
+ return "NEWMAIL";
+}
+
+mail::smapNEWMAIL::smapNEWMAIL(mail::callback *callbackArg,
+ bool isOpenArg)
+ : isOpen(isOpenArg), expectedFetchCount(0), fetchCount(0),
+ noopSent(false)
+{
+ defaultCB= callbackArg;
+}
+
+mail::smapNEWMAIL::~smapNEWMAIL()
+{
+}
+
+void mail::smapNEWMAIL::installed(imap &imapAccount)
+{
+ imapFOLDERinfo *p=myimap->currentFolder;
+
+ if (p)
+ {
+ size_t n=p->index.size();
+
+ if (p->exists < n)
+ {
+ ostringstream o;
+
+ o << "FETCH " << p->exists+1 << "-" << n
+ << " FLAGS UID\n" << flush;
+
+ expectedFetchCount=(n - p->exists)*2;
+
+ imapAccount.imapcmd("", o.str());
+ return;
+ }
+ }
+
+ smapHandler::ok("OK");
+ imapAccount.uninstallHandler(this);
+}
+
+//
+// Report on our progress
+//
+
+void mail::smapNEWMAIL::fetchedIndexInfo()
+{
+ ++fetchCount;
+
+ if (fetchCount <= expectedFetchCount && defaultCB)
+ defaultCB->reportProgress(0, 0,
+ fetchCount/2,
+ expectedFetchCount/2);
+}
+
+bool mail::smapNEWMAIL::ok(std::string str)
+{
+ if (!noopSent)
+ {
+ imapFOLDERinfo *p=myimap->currentFolder;
+
+ while (p && p->exists < p->index.size() &&
+ p->index[p->exists].uid.size() > 0)
+ ++p->exists;
+
+ noopSent=true;
+ doDestroy=false;
+ myimap->imapcmd("", "NOOP\n"); // Get a snapshot
+ return true;
+ }
+
+ if (myimap->currentFolder)
+ {
+ if (isOpen)
+ myimap->currentFolder->opened();
+ else
+ myimap->currentFolder->folderCallback.newMessages();
+ }
+ return smapHandler::ok(str);
+}
+
+bool mail::smapNEWMAIL::fail(std::string str)
+{
+ if (myimap->currentFolder)
+ {
+ if (isOpen)
+ myimap->currentFolder->opened();
+ else
+ myimap->currentFolder->folderCallback.newMessages();
+ }
+
+ return smapHandler::fail(str);
+}