File: addressbook.H

package info (click to toggle)
cone 0.75-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 31,040 kB
  • ctags: 13,930
  • sloc: ansic: 90,648; cpp: 79,781; sh: 18,355; perl: 3,218; makefile: 1,611; yacc: 289; sed: 16
file content (160 lines) | stat: -rw-r--r-- 4,049 bytes parent folder | download | duplicates (2)
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
/* $Id: addressbook.H,v 1.3 2005/02/24 03:39:09 mrsam Exp $
**
** Copyright 2002, Double Precision Inc.
**
** See COPYING for distribution information.
*/
#ifndef libmail_addressbook_H
#define libmail_addressbook_H

#include "libmail_config.h"

#include "mail.H"
#include "namespace.H"
#include "objectmonitor.H"

#include <string>
#include <list>
#include <vector>

LIBMAIL_START

class address;
class emailAddress;

/////////////////////////////////////////////////////////////////////////////
//
// Turn any folder into an address book.
//
// Create a mail::account object and a mail::folder object, then use this
// object to create an address book-type interface to them.
//
// This is implemented by saving each address book entry as a message in
// the folder.  The message contains of a minimum set of mail headers.
// The Subject: header contains the address book nickname/handle.
// The address book entry is saved in a text/x-libmail-addressbok MIME section.
// There's also a brief text/plain section that informs the human reader to
// stay out of this folder and message.
//
// At this time, text/x-libmail-addressbok MIME section itself consists of a
// single Address: header (folded in the similar fashion as real mail headers),
// containing an RFC 2822-formatted address list, that uses the UTF-8
// character set.

class addressbook : public mail::obj,
		    private mail::callback::folder {

	//
	// Handle folder update callbacks.
	//

	void newMessages();
	void messagesRemoved(std::vector< std::pair<size_t, size_t> > &);
	void messageChanged(size_t n);

	mail::account *server;
	mail::folder *folder;
	//
	// The address book is here.
	//
	// server may NOT be used for any other purposes, by the application.
	//
	// server and folder may NOT be destroyed until this object is
	// destroyed first.

	//
	// The address book index.
	//

	class Index {
	public:
		Index();
		~Index();

		std::string nickname;	// Nickname, in app's charset
		std::string uid;	// Nickname uid.
	};

	std::vector<Index> index;

	class Add;
	class Del;
	class GetIndex;
	class Open;

	template<class T> class GetAddressList;
	template<class T> class Search;

	//
	// Message #messageNumber has the following subject.
	// The subject line stores the nickname, decode it.
	//
	// The subject line uses the UTF-8 character set, and contains the
	// nickname inside brackets.  setIndex() parses it out.
	//

	void setIndex(size_t messageNumber, std::string subject);

public:
	friend class Add;
	friend class Del;
	friend class GetIndex;
	friend class Open;

	friend class Search<mail::address>;
	friend class Search<mail::emailAddress>;

	friend class GetAddressList<mail::address>;
	friend class GetAddressList<mail::emailAddress>;

	class Entry {
	public:
		Entry();
		~Entry();

		std::string nickname;	// Local charset

		std::vector<mail::emailAddress> addresses;
	};

	addressbook(mail::account *serverArg,
		    mail::folder *folderArg);
	~addressbook();

	// Open the address book.  Read the folder's contents, and initialize
	// the address book index.
	void open(mail::callback &callback);

	// Add a new address book entry.
	void addEntry(Entry &newEntry, std::string olduid,
		      mail::callback &callback);

	void importEntries(std::list<Entry> &newEntries,
			   mail::callback &callback);

	// Delete an address book entry.
	void del(std::string uid, mail::callback &callback);

	// Initialize listArg with the contents of the address book.
	// listArg is a pair of nickname/uid.
	void getIndex( std::list< std::pair<std::string, std::string> >
		       &listArg, mail::callback &callback);

	// Read address book entry #uid.  Addresses are added to addrListArg.
	template<class T>
	void getEntry( std::string uid,
		       std::vector<T> &addrListArg,
		       mail::callback &callback);

	// Search the address book for the nickname.  Initialize addrListArg
	// if found.
	template<class T>
	void searchNickname(std::string nickname,
			    std::vector<T> &addrListArg,
			    mail::callback &callback);
};

LIBMAIL_END

#endif