tdeioslave/imap4

imap4.h
1 #ifndef _IMAP4_H
2 #define _IMAP4_H
3 /**********************************************************************
4  *
5  * imap4.h - IMAP4rev1 KIOSlave
6  * Copyright (C) 2001-2002 Michael Haeckel <haeckel@kde.org>
7  * Copyright (C) 1999 John Corey <jcorey@fruity.ath.cx>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  * Send comments and bug fixes to jcorey@fruity.ath.cx
24  *
25  *********************************************************************/
26 
27 #include "imapparser.h"
28 #include "mimeio.h"
29 
30 #include <tdeio/tcpslavebase.h>
31 #include <tqbuffer.h>
32 
33 #define IMAP_BUFFER 8192
34 
36 enum IMAP_TYPE
37 {
38  ITYPE_UNKNOWN, /*< unknown type */
39  ITYPE_DIR, /*< Object is a directory. i.e. does not contain message, just mailboxes */
40  ITYPE_BOX, /*< Object is a mailbox. i.e. contains mails */
41  ITYPE_DIR_AND_BOX, /*< Object contains both mails and mailboxes */
42  ITYPE_MSG, /*< Object is a mail */
43  ITYPE_ATTACH /*< Object is an attachment */
44 };
45 
47 class IMAP4Protocol:public
48  TDEIO::TCPSlaveBase,
49  public
50  imapParser,
51  public
52  mimeIO
53 {
54 
55 public:
56 
57  // reimplement the TCPSlave
58  IMAP4Protocol (const TQCString & pool, const TQCString & app, bool isSSL);
59  virtual ~IMAP4Protocol ();
60 
61  virtual void openConnection();
62  virtual void closeConnection();
63 
64  virtual void setHost (const TQString & _host, int _port, const TQString & _user,
65  const TQString & _pass);
72  virtual void get (const KURL & _url);
76  virtual void stat (const KURL & _url);
77  virtual void slave_status ();
81  virtual void del (const KURL & _url, bool isFile);
86  virtual void special (const TQByteArray & data);
90  virtual void listDir (const KURL & _url);
91  virtual void setSubURL (const KURL & _url);
92  virtual void dispatch (int command, const TQByteArray & data);
96  virtual void mkdir (const KURL & url, int permissions);
97  virtual void put (const KURL & url, int permissions, bool overwrite,
98  bool resume);
99  virtual void rename (const KURL & src, const KURL & dest, bool overwrite);
100  virtual void copy (const KURL & src, const KURL & dest, int permissions,
101  bool overwrite);
102 
106  virtual void parseRelay (const TQByteArray & buffer);
107 
111  virtual void parseRelay (ulong);
112 
115  virtual bool parseRead (TQByteArray &buffer,ulong len,ulong relay=0);
116 
119  virtual bool parseReadLine (TQByteArray & buffer, ulong relay = 0);
120 
123  virtual void parseWriteLine (const TQString &);
124 
126  virtual int outputLine (const TQCString & _str, int len = -1);
127 
129  virtual void flushOutput(TQString contentEncoding = TQString());
130 
131 protected:
132 
133  // select or examine the box if needed
134  bool assureBox (const TQString & aBox, bool readonly);
135 
136  ssize_t myRead(void *data, ssize_t len);
137 
145  enum IMAP_TYPE
146  parseURL (const KURL & _url, TQString & _box, TQString & _section,
147  TQString & _type, TQString & _uid, TQString & _validity,
148  TQString & _hierarchyDelimiter, TQString & _info,
149  bool cache = false);
150  TQString getMimeType (enum IMAP_TYPE);
151 
152  bool makeLogin ();
153 
154  void outputLineStr (const TQString & _str)
155  {
156  outputLine (_str.latin1 (), _str.length());
157  }
158  void doListEntry (const KURL & _url, int stretch, imapCache * cache = NULL,
159  bool withFlags = FALSE, bool withSubject = FALSE);
160 
166  void doListEntry (const KURL & url, const TQString & myBox,
167  const imapList & item, bool appendPath = true);
168 
170  void specialACLCommand( int command, TQDataStream& stream );
171 
173  void specialAnnotateMoreCommand( int command, TQDataStream& stream );
174  void specialQuotaCommand( int command, TQDataStream& stream );
175 
177  void specialSearchCommand( TQDataStream& );
178 
180  void specialCustomCommand( TQDataStream& );
181 
182 private:
183 
184  // This method behaves like the above method but takes an already encoded url,
185  // so you don't have to call KURL::url() for every mail.
186  void doListEntry (const TQString & encodedUrl, int stretch, imapCache * cache = NULL,
187  bool withFlags = FALSE, bool withSubject = FALSE);
188 
189  TQString myHost, myUser, myPass, myAuth, myTLS;
190  int myPort;
191  bool mySSL;
192 
193  bool relayEnabled, cacheOutput, decodeContent;
194  TQByteArray outputCache;
195  TQBuffer outputBuffer;
196  TQ_ULONG outputBufferIndex;
197  TDEIO::filesize_t mProcessedSize;
198 
199  char readBuffer[IMAP_BUFFER];
200  ssize_t readBufferLen;
201  int readSize;
202  TQDateTime mTimeOfLastNoop;
203 };
204 
205 #endif
IOSlave derived class.
Definition: imap4.h:53
virtual void del(const KURL &_url, bool isFile)
delete a mailbox
Definition: imap4.cpp:1083
virtual void parseRelay(const TQByteArray &buffer)
reimplement the parser relay hook to send the fetched data directly to an upper level
Definition: imap4.cpp:653
virtual void special(const TQByteArray &data)
Capabilites, NOOP, (Un)subscribe, Change status, Change ACL.
Definition: imap4.cpp:1224
virtual void listDir(const KURL &_url)
list a directory/mailbox
Definition: imap4.cpp:406
void specialSearchCommand(TQDataStream &)
Search current folder, the search string is passed as SECTION.
Definition: imap4.cpp:1549
void specialCustomCommand(TQDataStream &)
Send a custom command to the server.
Definition: imap4.cpp:1577
virtual void mkdir(const KURL &url, int permissions)
create a mailbox
Definition: imap4.cpp:923
void specialAnnotateMoreCommand(int command, TQDataStream &stream)
Send an annotation command which is identified by command.
Definition: imap4.cpp:1656
virtual void stat(const KURL &_url)
stat a mailbox, message, attachment
Definition: imap4.cpp:1842
virtual bool parseReadLine(TQByteArray &buffer, ulong relay=0)
reimplement the parser
Definition: imap4.cpp:715
virtual void parseWriteLine(const TQString &)
reimplement the parser
Definition: imap4.cpp:2224
virtual void get(const KURL &_url)
get a message or part of a message the data is normally sent as we get it from the server if you want...
Definition: imap4.cpp:194
virtual int outputLine(const TQCString &_str, int len=-1)
reimplement the mimeIO
Definition: imap4.cpp:2604
void specialACLCommand(int command, TQDataStream &stream)
Send an ACL command which is identified by command.
Definition: imap4.cpp:1447
enum IMAP_TYPE parseURL(const KURL &_url, TQString &_box, TQString &_section, TQString &_type, TQString &_uid, TQString &_validity, TQString &_hierarchyDelimiter, TQString &_info, bool cache=false)
Parses the given URL The return values are set by parsing the URL and querying the server.
Definition: imap4.cpp:2474
virtual void flushOutput(TQString contentEncoding=TQString())
send out cached data to the application
Definition: imap4.cpp:2633
virtual bool parseRead(TQByteArray &buffer, ulong len, ulong relay=0)
reimplement the parser read at least len bytes
Definition: imap4.cpp:680
Definition: mimeio.h:29