52 |
|
#ifndef _IMAPHandler_h_ |
53 |
|
#define _IMAPHandler_h_ |
54 |
|
|
55 |
< |
#include "WinXPFAQPoll.h" |
56 |
< |
#include <jni.h> |
55 |
> |
#include <iostream> |
56 |
> |
#include <string> |
57 |
> |
#include <cstdlib> |
58 |
> |
#include <cstdio> |
59 |
> |
|
60 |
> |
using namespace std; |
61 |
> |
|
62 |
> |
// Lovely C Sockets! |
63 |
> |
#ifdef _WIN32 |
64 |
> |
|
65 |
> |
// Windows Sockets |
66 |
> |
#include <winsock2.h> |
67 |
> |
#include <windows.h> |
68 |
> |
|
69 |
> |
#else |
70 |
> |
|
71 |
> |
// BSD Sockets |
72 |
> |
#include <unistd.h> |
73 |
> |
#include <sys/types.h> |
74 |
> |
#include <sys/socket.h> |
75 |
> |
#include <netinet/in.h> |
76 |
> |
#include <netdb.h> |
77 |
> |
|
78 |
> |
#define INVALID_SOCKET -1 |
79 |
> |
#define SOCKET_ERROR -1 |
80 |
> |
|
81 |
> |
typedef int SOCKET; |
82 |
> |
|
83 |
> |
inline int closesocket(SOCKET s) { return close(s); } |
84 |
> |
|
85 |
> |
#endif // _WIN32 |
86 |
> |
|
87 |
> |
#include <openssl/ssl.h> |
88 |
> |
#include <openssl/err.h> |
89 |
> |
#include <openssl/rand.h> |
90 |
> |
|
91 |
> |
extern string program; |
92 |
> |
extern bool debug; |
93 |
|
|
94 |
|
class IMAPHandler |
95 |
|
{ |
96 |
|
private: |
97 |
< |
char* jarPath; |
98 |
< |
JavaVMOption options[1]; |
99 |
< |
JNIEnv* env; |
100 |
< |
JavaVM* jvm; |
101 |
< |
JavaVMInitArgs vm_args; |
102 |
< |
long status; |
103 |
< |
jclass cls; |
104 |
< |
jmethodID mid; |
105 |
< |
jobject obj; |
106 |
< |
void setJarPath(); |
107 |
< |
string imap(char* imap); |
108 |
< |
string imap(char* imap, const string& args); |
109 |
< |
string imap(char* imap, const string& args, const string& message); |
97 |
> |
#ifdef _WIN32 |
98 |
> |
WSADATA data; |
99 |
> |
#endif // _WIN32 |
100 |
> |
SOCKET sock; |
101 |
> |
SSL_CTX* ctx; |
102 |
> |
SSL* ssl; |
103 |
> |
bool tls; |
104 |
> |
char* buffer; |
105 |
> |
char letter; |
106 |
> |
unsigned number; |
107 |
> |
bool success; |
108 |
> |
string command(); |
109 |
> |
string imap(const string& imap); |
110 |
> |
string imap(const string& imap, const string& args); |
111 |
> |
string imap(const string& imap, const string& args, const string& message); |
112 |
> |
void putline(const string line = ""); |
113 |
> |
string getline(); |
114 |
> |
void error(const string& prefix, bool host = false); |
115 |
> |
void error(const string& prefix, int code); |
116 |
|
public: |
117 |
< |
IMAPHandler(const string& host, unsigned port); |
117 |
> |
IMAPHandler(const string& server, bool tls = false); |
118 |
|
~IMAPHandler(); |
119 |
< |
string capability() { return imap("capability"); } |
120 |
< |
string noop() { return imap("noop"); } |
121 |
< |
string logout() { return imap("logout"); } |
122 |
< |
string login(const string& args) { return imap("login", args); } |
119 |
> |
string capability() { return imap("CAPABILITY"); } |
120 |
> |
string starttls(); |
121 |
> |
string noop() { return imap("NOOP"); } |
122 |
> |
string logout() { return imap("LOGOUT"); } |
123 |
> |
string login(const string& args) { return imap("LOGIN", args); } |
124 |
|
string select(const string& args) { return imap("select", args); } |
125 |
|
string examine(const string& args) { return imap("examine", args); } |
126 |
|
string create(const string& args) { return imap("create", args); } |
143 |
|
string store(const string& args) { return imap("store", args); } |
144 |
|
string copy(const string& args) { return imap("copy", args); } |
145 |
|
string uid(const string& args) { return imap("uid", args); } |
146 |
< |
bool successful(); |
146 |
> |
bool successful() { return success; } |
147 |
|
}; |
148 |
|
|
149 |
|
#endif // _IMAPHandler_h_ |