1 |
< |
/* ============================================================================ |
2 |
< |
* Douglas Thrift's Web Contact License |
3 |
< |
* |
4 |
< |
* Copyright (C) 2002, Douglas Thrift. All Rights Reserved. |
5 |
< |
* |
6 |
< |
* Redistribution and use in source and binary forms, with or without |
7 |
< |
* modification, are permitted provided that the following conditions are met: |
8 |
< |
* |
9 |
< |
* 1. Redistributions of source code must retain the above copyright notice, |
10 |
< |
* this list of conditions and the following disclaimer. |
11 |
< |
* |
12 |
< |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
13 |
< |
* this list of conditions and the following disclaimer in the documentation |
14 |
< |
* and/or other materials provided with the distribution. |
15 |
< |
* |
16 |
< |
* 3. The end-user documentation included with the redistribution, if any, must |
17 |
< |
* include the following acknowledgment: |
18 |
< |
* |
19 |
< |
* "This product includes software developed by Douglas Thrift |
20 |
< |
* (http://computers.douglasthrift.net/webcontact.html)." |
21 |
< |
* |
22 |
< |
* Alternately, this acknowledgment may appear in the software itself, if |
23 |
< |
* and wherever such third-party acknowledgments normally appear. |
24 |
< |
* |
25 |
< |
* 4. The names "Douglas Thrift" and "Douglas Thrift's Web Contact" must not be |
26 |
< |
* used to endorse or promote products derived from this software without |
27 |
< |
* specific prior written permission. For written permission, please visit |
28 |
< |
* http://www.douglasthrift.net/contact.html for contact information. |
29 |
< |
* |
30 |
< |
* 5. Products derived from this software may not be called "Douglas Thrift's |
31 |
< |
* Web Contact", nor may "Douglas Thrift's Web Contact" appear in their |
32 |
< |
* name, without prior written permission. |
33 |
< |
* |
34 |
< |
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
35 |
< |
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
36 |
< |
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
37 |
< |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
38 |
< |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
39 |
< |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
40 |
< |
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
41 |
< |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
42 |
< |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
43 |
< |
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
44 |
< |
* ============================================================================ |
45 |
< |
*/ |
46 |
< |
// Windows XP FAQ Poll |
1 |
> |
// IMAP Handler |
2 |
|
// |
3 |
|
// Douglas Thrift |
4 |
|
// |
7 |
|
#ifndef _IMAPHandler_h_ |
8 |
|
#define _IMAPHandler_h_ |
9 |
|
|
10 |
< |
#include "WinXPFAQPoll.h" |
11 |
< |
#include <jni.h> |
10 |
> |
#include <iostream> |
11 |
> |
#include <sstream> |
12 |
> |
#include <string> |
13 |
> |
#include <cstdlib> |
14 |
> |
#include <cstdio> |
15 |
> |
|
16 |
> |
using namespace std; |
17 |
> |
|
18 |
> |
// Lovely C Sockets! |
19 |
> |
#ifdef _WIN32 |
20 |
> |
|
21 |
> |
// Windows Sockets |
22 |
> |
#include <winsock2.h> |
23 |
> |
#include <windows.h> |
24 |
> |
|
25 |
> |
#else |
26 |
> |
|
27 |
> |
// BSD Sockets |
28 |
> |
#include <unistd.h> |
29 |
> |
#include <sys/types.h> |
30 |
> |
#include <sys/socket.h> |
31 |
> |
#include <netinet/in.h> |
32 |
> |
#include <netdb.h> |
33 |
> |
|
34 |
> |
#define INVALID_SOCKET -1 |
35 |
> |
#define SOCKET_ERROR -1 |
36 |
> |
|
37 |
> |
typedef int SOCKET; |
38 |
> |
|
39 |
> |
inline int closesocket(SOCKET s) { return close(s); } |
40 |
> |
|
41 |
> |
#endif // _WIN32 |
42 |
> |
|
43 |
> |
#include <openssl/ssl.h> |
44 |
> |
#include <openssl/err.h> |
45 |
> |
#include <openssl/rand.h> |
46 |
> |
|
47 |
> |
extern string program; |
48 |
> |
extern bool debug; |
49 |
|
|
50 |
|
class IMAPHandler |
51 |
|
{ |
52 |
|
private: |
53 |
< |
char* jarPath; |
54 |
< |
JavaVMOption options[1]; |
55 |
< |
JNIEnv* env; |
56 |
< |
JavaVM* jvm; |
57 |
< |
JavaVMInitArgs vm_args; |
58 |
< |
long status; |
59 |
< |
jclass cls; |
60 |
< |
jmethodID mid; |
61 |
< |
jobject obj; |
62 |
< |
void setJarPath(); |
63 |
< |
string imap(char* imap); |
64 |
< |
string imap(char* imap, const string& args); |
65 |
< |
string imap(char* imap, const string& args, const string& message); |
53 |
> |
#ifdef _WIN32 |
54 |
> |
WSADATA data; |
55 |
> |
#endif // _WIN32 |
56 |
> |
SOCKET sock; |
57 |
> |
SSL_CTX* ctx; |
58 |
> |
SSL* ssl; |
59 |
> |
bool tls; |
60 |
> |
char* buffer; |
61 |
> |
char letter; |
62 |
> |
unsigned number; |
63 |
> |
bool success; |
64 |
> |
string command(); |
65 |
> |
string imap(const string& imap); |
66 |
> |
string imap(const string& imap, const string& args); |
67 |
> |
string imap(const string& imap, const string& args, const string& message); |
68 |
> |
void putline(const string line = ""); |
69 |
> |
string getline(); |
70 |
> |
void error(const string& prefix, bool host = false); |
71 |
> |
void error(const string& prefix, int code); |
72 |
|
public: |
73 |
< |
IMAPHandler(const string& host, unsigned port); |
73 |
> |
IMAPHandler(const string& server, bool tls = false); |
74 |
|
~IMAPHandler(); |
75 |
< |
string capability() { return imap("capability"); } |
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); } |
75 |
> |
string capability() { return imap("CAPABILITY"); } |
76 |
> |
string starttls(); |
77 |
> |
string noop() { return imap("NOOP"); } |
78 |
> |
string logout() { return imap("LOGOUT"); } |
79 |
> |
string login(const string& args) { return imap("LOGIN", args); } |
80 |
> |
string select(const string& args) { return imap("SELECT", args); } |
81 |
> |
string examine(const string& args) { return imap("EXAMINE", args); } |
82 |
> |
string create(const string& args) { return imap("CREATE", args); } |
83 |
> |
string delete_(const string& args) { return imap("DELETE", args); } |
84 |
> |
string rename(const string& args) { return imap("RENAME", args); } |
85 |
> |
string subscribe(const string& args) { return imap("SUBSCRIBE", args); } |
86 |
> |
string unsubscribe(const string& args) { return imap("UNSUBSCRIBE", args); } |
87 |
> |
string list(const string& args) { return imap("LIST", args); } |
88 |
> |
string lsub(const string& args) { return imap("LSUB", args); } |
89 |
> |
string status_(const string& args) { return imap("STATUS", args); } |
90 |
|
string append(const string& args, const string& message) |
91 |
|
{ |
92 |
< |
return imap("append", args, message); |
92 |
> |
return imap("APPEND", args, message); |
93 |
|
} |
94 |
< |
string check() { return imap("check"); } |
95 |
< |
string close() { return imap("close"); } |
96 |
< |
string expunge() { return imap("expunge"); } |
97 |
< |
string search(const string& args) { return imap("search", args); } |
98 |
< |
string fetch(const string& args) { return imap("fetch", args); } |
99 |
< |
string store(const string& args) { return imap("store", args); } |
100 |
< |
string copy(const string& args) { return imap("copy", args); } |
101 |
< |
string uid(const string& args) { return imap("uid", args); } |
102 |
< |
bool successful(); |
94 |
> |
string check() { return imap("CHECK"); } |
95 |
> |
string close() { return imap("CLOSE"); } |
96 |
> |
string expunge() { return imap("EXPUNGE"); } |
97 |
> |
string search(const string& args) { return imap("SEARCH", args); } |
98 |
> |
string fetch(const string& args) { return imap("FETCH", args); } |
99 |
> |
string store(const string& args) { return imap("STORE", args); } |
100 |
> |
string copy(const string& args) { return imap("COPY", args); } |
101 |
> |
string uid(const string& args) { return imap("UID", args); } |
102 |
> |
bool successful() { return success; } |
103 |
|
}; |
104 |
|
|
105 |
|
#endif // _IMAPHandler_h_ |