summaryrefslogtreecommitdiffstats
path: root/tdeioslaves/sieve/sieve.h
blob: d25b1d5713eb963e52b3b94740ec9350236fad94 (plain)
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
/***************************************************************************
                          sieve.h  -  description
                             -------------------
    begin                : Thu Dec 20 18:47:08 EST 2001
    copyright            : (C) 2001 by Hamish Rodda
    email                : meddie@yoyo.cc.monash.edu.au
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License version 2 as     *
 *   published by the Free Software Foundation.                            *
 *                                                                         *
 ***************************************************************************/
#ifndef __sieve_h__
#define __sieve_h__

#include <tdeio/tcpslavebase.h>
#include <tdeio/authinfo.h>

#include <tqstring.h>
#include <tqcstring.h>
#include <tqstringlist.h>

class KDESasl;
class KURL;


class kio_sieveResponse
{
public:
	enum responses { NONE, KEY_VAL_PAIR, ACTION, QUANTITY };

	kio_sieveResponse();

	const uint& getType() const;

	const TQCString& getAction() const;
	const uint getQuantity() const;
	const TQCString& getKey() const;
	const TQCString& getVal() const;
	const TQCString& getExtra() const;

	void setQuantity(const uint& quantity);
	void setAction(const TQCString& newAction);
	void setKey(const TQCString& newKey);
	void setVal(const TQCString& newVal);
	void setExtra(const TQCString& newExtra);

	void clear();

protected:
	uint		rType;
	uint		quantity;
	TQCString	key;
	TQCString	val;
	TQCString	extra;
};

class kio_sieveProtocol : public TDEIO::TCPSlaveBase
{

public:
	enum connectionModes { NORMAL, CONNECTION_ORIENTED };
	enum Results { OK, NO, BYE, OTHER };

	kio_sieveProtocol(const TQCString &pool_socket, const TQCString &app_socket);
	virtual ~kio_sieveProtocol();

	virtual void mimetype(const KURL& url);
	virtual void get(const KURL& url);
	virtual void put(const KURL& url, int permissions, bool overwrite, bool resume);
	virtual void del(const KURL &url, bool isfile);

	virtual void listDir(const KURL& url);
	virtual void chmod(const KURL& url, int permissions);
	virtual void stat(const KURL& url);

	virtual void setHost(const TQString &host, int port, const TQString &user, const TQString &pass);
	virtual void openConnection();
	virtual void closeConnection();
	//virtual void slave_status();

	/**
	 * Special commands supported by this slave:
	 * 1 - activate script
	 * 2 - deactivate (all - only one active at any one time) scripts
	 * 3 - request capabilities, returned as metadata
	 */
	virtual void special(const TQByteArray &data);
	bool activate(const KURL& url);
	bool deactivate();

protected:
	bool connect(bool useTLSIfAvailable = true);
	bool authenticate();
	void disconnect(bool forcibly = false);
	void changeCheck( const KURL &url );

	bool sendData(const TQCString &data);
	bool receiveData(bool waitForData = true, TQCString *reparse = 0);
	bool operationSuccessful();
	int operationResult();

	bool parseCapabilities(bool requestCapabilities = false);
  bool saslInteract( void *in, TDEIO::AuthInfo &ai );

	// IOSlave global data
	uint				m_connMode;

	// Host-specific data
	TQStringList			m_sasl_caps;
	bool				m_supportsTLS;

	// Global server respose class
	kio_sieveResponse	r;

	// connection details
	TQString				m_sServer;
	TQString				m_sUser;
	TQString				m_sPass;
	TQString				m_sAuth;
	bool				m_shouldBeConnected;
        bool m_allowUnencrypted;

private:
	bool requestCapabilitiesAfterStartTLS() const;

	TQString m_implementation;
};

#endif