00001 #ifndef _IMAP4_H
00002 #define _IMAP4_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "imapparser.h"
00028 #include "mimeio.h"
00029
00030 #include <kio/tcpslavebase.h>
00031 #include <qbuffer.h>
00032
00033 #define IMAP_BUFFER 8192
00034
00036 enum IMAP_TYPE
00037 {
00038 ITYPE_UNKNOWN,
00039 ITYPE_DIR,
00040 ITYPE_BOX,
00041 ITYPE_DIR_AND_BOX,
00042 ITYPE_MSG,
00043 ITYPE_ATTACH
00044 };
00045
00047 class IMAP4Protocol:public
00048 KIO::TCPSlaveBase,
00049 public
00050 imapParser,
00051 public
00052 mimeIO
00053 {
00054
00055 public:
00056
00057
00058 IMAP4Protocol (const QCString & pool, const QCString & app, bool isSSL);
00059 virtual ~IMAP4Protocol ();
00060
00061 virtual void openConnection();
00062 virtual void closeConnection();
00063
00064 virtual void setHost (const QString & _host, int _port, const QString & _user,
00065 const QString & _pass);
00072 virtual void get (const KURL & _url);
00076 virtual void stat (const KURL & _url);
00077 virtual void slave_status ();
00081 virtual void del (const KURL & _url, bool isFile);
00086 virtual void special (const QByteArray & data);
00090 virtual void listDir (const KURL & _url);
00091 virtual void setSubURL (const KURL & _url);
00092 virtual void dispatch (int command, const QByteArray & data);
00096 virtual void mkdir (const KURL & url, int permissions);
00097 virtual void put (const KURL & url, int permissions, bool overwrite,
00098 bool resume);
00099 virtual void rename (const KURL & src, const KURL & dest, bool overwrite);
00100 virtual void copy (const KURL & src, const KURL & dest, int permissions,
00101 bool overwrite);
00102
00106 virtual void parseRelay (const QByteArray & buffer);
00107
00111 virtual void parseRelay (ulong);
00112
00115 virtual bool parseRead (QByteArray &buffer,ulong len,ulong relay=0);
00116
00119 virtual bool parseReadLine (QByteArray & buffer, ulong relay = 0);
00120
00123 virtual void parseWriteLine (const QString &);
00124
00126 virtual int outputLine (const QCString & _str, int len = -1);
00127
00129 virtual void flushOutput(QString contentEncoding = QString::null);
00130
00131 protected:
00132
00133
00134 bool assureBox (const QString & aBox, bool readonly);
00135
00136 ssize_t myRead(void *data, ssize_t len);
00137
00145 enum IMAP_TYPE
00146 parseURL (const KURL & _url, QString & _box, QString & _section,
00147 QString & _type, QString & _uid, QString & _validity,
00148 QString & _hierarchyDelimiter, QString & _info,
00149 bool cache = false);
00150 QString getMimeType (enum IMAP_TYPE);
00151
00152 bool makeLogin ();
00153
00154 void outputLineStr (const QString & _str)
00155 {
00156 outputLine (_str.latin1 (), _str.length());
00157 }
00158 void doListEntry (const KURL & _url, int stretch, imapCache * cache = NULL,
00159 bool withFlags = FALSE, bool withSubject = FALSE);
00160
00166 void doListEntry (const KURL & url, const QString & myBox,
00167 const imapList & item, bool appendPath = true);
00168
00170 void specialACLCommand( int command, QDataStream& stream );
00171
00173 void specialAnnotateMoreCommand( int command, QDataStream& stream );
00174 void specialQuotaCommand( int command, QDataStream& stream );
00175
00177 void specialSearchCommand( QDataStream& );
00178
00180 void specialCustomCommand( QDataStream& );
00181
00182 private:
00183
00184
00185
00186 void doListEntry (const QString & encodedUrl, int stretch, imapCache * cache = NULL,
00187 bool withFlags = FALSE, bool withSubject = FALSE);
00188
00189 QString myHost, myUser, myPass, myAuth, myTLS;
00190 int myPort;
00191 bool mySSL;
00192
00193 bool relayEnabled, cacheOutput, decodeContent;
00194 QByteArray outputCache;
00195 QBuffer outputBuffer;
00196 Q_ULONG outputBufferIndex;
00197 KIO::filesize_t mProcessedSize;
00198
00199 char readBuffer[IMAP_BUFFER];
00200 ssize_t readBufferLen;
00201 int readSize;
00202 QDateTime mTimeOfLastNoop;
00203 };
00204
00205 #endif