1 /*
2 ** Copyright 2002, Double Precision Inc.
3 **
4 ** See COPYING for distribution information.
5 */
6 #include "libmail_config.h"
7 #include "addressbooksearch.H"
8 
9 using namespace std;
10 
11 template<class T>
Search(mail::addressbook * addressBookArg,vector<T> & addrListArg,mail::callback & callbackArg)12 mail::addressbook::Search<T>::Search(mail::addressbook *addressBookArg,
13 				  vector<T> &addrListArg,
14 				  mail::callback &callbackArg)
15 	: addressBook(addressBookArg),
16 	  addrList(addrListArg),
17 	  callback(callbackArg)
18 {
19 }
20 
21 template<class T>
~Search()22 mail::addressbook::Search<T>::~Search()
23 {
24 }
25 
26 template<class T>
success(std::string msg)27 void mail::addressbook::Search<T>::success(std::string msg)
28 {
29 	go();
30 }
31 
32 template<class T>
fail(std::string msg)33 void mail::addressbook::Search<T>::fail(std::string msg)
34 {
35 	try {
36 		callback.fail(msg);
37 		delete this;
38 	} catch (...) {
39 		delete this;
40 		LIBMAIL_THROW(LIBMAIL_THROW_EMPTY);
41 	}
42 }
43 
44 template<class T>
reportProgress(size_t bytesCompleted,size_t bytesEstimatedTotal,size_t messagesCompleted,size_t messagesEstimatedTotal)45 void mail::addressbook::Search<T>::reportProgress(size_t bytesCompleted,
46 					       size_t bytesEstimatedTotal,
47 
48 					       size_t messagesCompleted,
49 					       size_t messagesEstimatedTotal)
50 {
51 	callback.reportProgress(bytesCompleted, bytesEstimatedTotal,
52 				messagesCompleted, messagesEstimatedTotal);
53 }
54 
55 template<class T>
go()56 void mail::addressbook::Search<T>::go()
57 {
58 	list<string>::iterator b=uidList.begin(), e=uidList.end();
59 
60 	if (b == e) // Finished the list.
61 	{
62 		try {
63 			callback.success("OK");
64 			delete this;
65 		} catch (...) {
66 			delete this;
67 			LIBMAIL_THROW(LIBMAIL_THROW_EMPTY);
68 		}
69 		return;
70 	}
71 
72 	// Just get the next address book entry.
73 
74 	string uid= *b;
75 
76 	uidList.erase(b);
77 
78 	addressBook->getEntry( uid, addrList, *this );
79 }
80 
81 template class mail::addressbook::Search<mail::address>;
82 template class mail::addressbook::Search<mail::emailAddress>;
83