kioslaves

imaplist.cc

Go to the documentation of this file.
00001 /**********************************************************************
00002  *
00003  *   imapinfo.cc  - IMAP4rev1 EXAMINE / SELECT handler
00004  *   Copyright (C) 2000 Sven Carstens
00005  *
00006  *   This program is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   This program is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with this program; if not, write to the Free Software
00018  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  *   Send comments and bug fixes to
00021  *
00022  *********************************************************************/
00023 
00024 /*
00025   References:
00026     RFC 2060 - Internet Message Access Protocol - Version 4rev1 - December 1996
00027     RFC 2192 - IMAP URL Scheme - September 1997
00028     RFC 1731 - IMAP Authentication Mechanisms - December 1994
00029                (Discusses KERBEROSv4, GSSAPI, and S/Key)
00030     RFC 2195 - IMAP/POP AUTHorize Extension for Simple Challenge/Response
00031              - September 1997 (CRAM-MD5 authentication method)
00032     RFC 2104 - HMAC: Keyed-Hashing for Message Authentication - February 1997
00033 
00034   Supported URLs:
00035     imap://server/ - Prompt for user/pass, list all folders in home directory
00036     imap://user:pass@server/ - Uses LOGIN to log in
00037     imap://user;AUTH=method:pass@server/ - Uses AUTHENTICATE to log in
00038 
00039     imap://server/folder/ - List messages in folder
00040  */
00041 
00042 #include "rfcdecoder.h"
00043 #include "imaplist.h"
00044 #include "imapparser.h"
00045 
00046 #include <kdebug.h>
00047 
00048 imapList::imapList (): parser_(0), noInferiors_ (false),
00049 noSelect_ (false), marked_ (false), unmarked_ (false), 
00050 hasChildren_ (false), hasNoChildren_ (false)
00051 {
00052 }
00053 
00054 imapList::imapList (const imapList & lr):parser_(lr.parser_),
00055 hierarchyDelimiter_ (lr.hierarchyDelimiter_),
00056 name_ (lr.name_),
00057 noInferiors_ (lr.noInferiors_),
00058 noSelect_ (lr.noSelect_), marked_ (lr.marked_), unmarked_ (lr.unmarked_),
00059 hasChildren_ (lr.hasChildren_), hasNoChildren_ (lr.hasNoChildren_),
00060 attributes_ (lr.attributes_)  
00061 {
00062 }
00063 
00064 imapList & imapList::operator = (const imapList & lr)
00065 {
00066   // Avoid a = a.
00067   if (this == &lr)
00068     return *this;
00069 
00070   parser_ = lr.parser_;
00071   hierarchyDelimiter_ = lr.hierarchyDelimiter_;
00072   name_ = lr.name_;
00073   noInferiors_ = lr.noInferiors_;
00074   noSelect_ = lr.noSelect_;
00075   marked_ = lr.marked_;
00076   unmarked_ = lr.unmarked_;
00077   hasChildren_ = lr.hasChildren_;
00078   hasNoChildren_ = lr.hasNoChildren_;
00079   attributes_ = lr.attributes_;
00080 
00081   return *this;
00082 }
00083 
00084 imapList::imapList (const QString & inStr, imapParser &parser)
00085 : parser_(&parser),
00086 noInferiors_ (false),
00087 noSelect_ (false),
00088 marked_ (false), unmarked_ (false), hasChildren_ (false),
00089 hasNoChildren_ (false)  
00090 {
00091   parseString s;
00092   s.data.duplicate(inStr.latin1(), inStr.length());
00093 
00094   if (s[0] != '(')
00095     return;                     //not proper format for us
00096 
00097   s.pos++;  // tie off (
00098 
00099   parseAttributes( s );
00100 
00101   s.pos++;  // tie off )
00102   parser_->skipWS (s);
00103 
00104   hierarchyDelimiter_ = parser_->parseOneWordC(s);
00105   if (hierarchyDelimiter_ == "NIL")
00106     hierarchyDelimiter_ = QString::null;
00107   name_ = rfcDecoder::fromIMAP (parser_->parseLiteral (s));  // decode modified UTF7
00108 }
00109 
00110 void imapList::parseAttributes( parseString & str )
00111 {
00112   QCString attribute, orig;
00113 
00114   while ( !str.isEmpty () && str[0] != ')' )
00115   {
00116     orig = parser_->parseOneWordC(str);
00117     attributes_ << orig;
00118     attribute = orig.lower();
00119     if (-1 != attribute.find ("\\noinferiors"))
00120       noInferiors_ = true;
00121     else if (-1 != attribute.find ("\\noselect"))
00122       noSelect_ = true;
00123     else if (-1 != attribute.find ("\\marked"))
00124       marked_ = true;
00125     else if (-1 != attribute.find ("\\unmarked"))
00126       unmarked_ = true;
00127     else if (-1 != attribute.find ("\\haschildren"))
00128       hasChildren_ = true;
00129     else if (-1 != attribute.find ("\\hasnochildren"))
00130       hasNoChildren_ = true;
00131     else
00132       kdDebug(7116) << "imapList::imapList: bogus attribute " << attribute << endl;
00133   }
00134 }
00135