ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/IMAPHandler/IMAPHandler.h
Revision: 108
Committed: 2003-03-31T20:49:38-08:00 (19 years, 8 months ago) by douglas
Content type: text/x-c
File size: 2853 byte(s)
Log Message:
Initial revision

File Contents

# Content
1 // IMAP Handler
2 //
3 // Douglas Thrift
4 //
5 // IMAPHandler.h
6
7 #ifndef _IMAPHandler_h_
8 #define _IMAPHandler_h_
9
10 #include <iostream>
11 #include <string>
12 #include <cstdlib>
13 #include <cstdio>
14
15 using namespace std;
16
17 // Lovely C Sockets!
18 #ifdef _WIN32
19
20 // Windows Sockets
21 #include <winsock2.h>
22 #include <windows.h>
23
24 #else
25
26 // BSD Sockets
27 #include <unistd.h>
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
31 #include <netdb.h>
32
33 #define INVALID_SOCKET -1
34 #define SOCKET_ERROR -1
35
36 typedef int SOCKET;
37
38 inline int closesocket(SOCKET s) { return close(s); }
39
40 #endif // _WIN32
41
42 #include <openssl/ssl.h>
43 #include <openssl/err.h>
44 #include <openssl/rand.h>
45
46 extern string program;
47 extern bool debug;
48
49 class IMAPHandler
50 {
51 private:
52 #ifdef _WIN32
53 WSADATA data;
54 #endif // _WIN32
55 SOCKET sock;
56 SSL_CTX* ctx;
57 SSL* ssl;
58 bool tls;
59 char* buffer;
60 char letter;
61 unsigned number;
62 bool success;
63 string command();
64 string imap(const string& imap);
65 string imap(const string& imap, const string& args);
66 string imap(const string& imap, const string& args, const string& message);
67 void putline(const string line = "");
68 string getline();
69 void error(const string& prefix, bool host = false);
70 void error(const string& prefix, int code);
71 public:
72 IMAPHandler(const string& server, bool tls = false);
73 ~IMAPHandler();
74 string capability() { return imap("CAPABILITY"); }
75 string starttls();
76 string noop() { return imap("NOOP"); }
77 string logout() { return imap("LOGOUT"); }
78 string login(const string& args) { return imap("LOGIN", args); }
79 string select(const string& args) { return imap("select", args); }
80 string examine(const string& args) { return imap("examine", args); }
81 string create(const string& args) { return imap("create", args); }
82 string delete_(const string& args) { return imap("delete", args); }
83 string rename(const string& args) { return imap("rename", args); }
84 string subscribe(const string& args) { return imap("subscribe", args); }
85 string unsubscribe(const string& args) { return imap("unsubscribe", args); }
86 string list(const string& args) { return imap("list", args); }
87 string lsub(const string& args) { return imap("lsub", args); }
88 string status_(const string& args) { return imap("status", args); }
89 string append(const string& args, const string& message)
90 {
91 return imap("append", args, message);
92 }
93 string check() { return imap("check"); }
94 string close() { return imap("close"); }
95 string expunge() { return imap("expunge"); }
96 string search(const string& args) { return imap("search", args); }
97 string fetch(const string& args) { return imap("fetch", args); }
98 string store(const string& args) { return imap("store", args); }
99 string copy(const string& args) { return imap("copy", args); }
100 string uid(const string& args) { return imap("uid", args); }
101 bool successful() { return success; }
102 };
103
104 #endif // _IMAPHandler_h_