kioslaves

imap4.h

Go to the documentation of this file.
00001 #ifndef _IMAP4_H
00002 #define _IMAP4_H
00003 /**********************************************************************
00004  *
00005  *   imap4.h  - IMAP4rev1 KIOSlave
00006  *   Copyright (C) 2001-2002  Michael Haeckel <haeckel@kde.org>
00007  *   Copyright (C) 1999  John Corey
00008  *
00009  *   This program is free software; you can redistribute it and/or modify
00010  *   it under the terms of the GNU General Public License as published by
00011  *   the Free Software Foundation; either version 2 of the License, or
00012  *   (at your option) any later version.
00013  *
00014  *   This program is distributed in the hope that it will be useful,
00015  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *   GNU General Public License for more details.
00018  *
00019  *   You should have received a copy of the GNU General Public License
00020  *   along with this program; if not, write to the Free Software
00021  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00022  *
00023  *   Send comments and bug fixes to jcorey@fruity.ath.cx
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, /*< unknown type */
00039   ITYPE_DIR,     /*< Object is a directory. i.e. does not contain message, just mailboxes */
00040   ITYPE_BOX,     /*< Object is a mailbox. i.e. contains mails */
00041   ITYPE_DIR_AND_BOX, /*< Object contains both mails and mailboxes */
00042   ITYPE_MSG,   /*< Object is a mail */
00043   ITYPE_ATTACH   /*< Object is an attachment */
00044 };
00045 
00047 class IMAP4Protocol:public
00048   KIO::TCPSlaveBase,
00049   public
00050   imapParser,
00051   public
00052   mimeIO
00053 {
00054 
00055 public:
00056 
00057   // reimplement the TCPSlave
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   // select or examine the box if needed
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   // This method behaves like the above method but takes an already encoded url,
00185   // so you don't have to call KURL::url() for every mail.
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