kioslave/imap4
imapinfo.cpp
00001 /********************************************************************** 00002 * 00003 * imapinfo.cc - IMAP4rev1 SELECT / EXAMINE handler 00004 * Copyright (C) 2000 Sven Carstens <s.carstens@gmx.de> 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 "imapinfo.h" 00043 #include "imapparser.h" 00044 00045 #include <kdebug.h> 00046 00047 imapInfo::imapInfo ():count_ (0), 00048 recent_ (0), 00049 unseen_ (0), 00050 uidValidity_ (0), 00051 uidNext_ (0), 00052 flags_ (0), 00053 permanentFlags_ (0), 00054 readWrite_ (false), 00055 countAvailable_ (false), 00056 recentAvailable_ (false), 00057 unseenAvailable_ (false), 00058 uidValidityAvailable_ (false), 00059 uidNextAvailable_ (false), 00060 flagsAvailable_ (false), 00061 permanentFlagsAvailable_ (false), readWriteAvailable_ (false) 00062 { 00063 } 00064 00065 imapInfo::imapInfo (const imapInfo & mi):count_ (mi.count_), 00066 recent_ (mi.recent_), 00067 unseen_ (mi.unseen_), 00068 uidValidity_ (mi.uidValidity_), 00069 uidNext_ (mi.uidNext_), 00070 flags_ (mi.flags_), 00071 permanentFlags_ (mi.permanentFlags_), 00072 readWrite_ (mi.readWrite_), 00073 countAvailable_ (mi.countAvailable_), 00074 recentAvailable_ (mi.recentAvailable_), 00075 unseenAvailable_ (mi.unseenAvailable_), 00076 uidValidityAvailable_ (mi.uidValidityAvailable_), 00077 uidNextAvailable_ (mi.uidNextAvailable_), 00078 flagsAvailable_ (mi.flagsAvailable_), 00079 permanentFlagsAvailable_ (mi.permanentFlagsAvailable_), 00080 readWriteAvailable_ (mi.readWriteAvailable_) 00081 { 00082 } 00083 00084 imapInfo & imapInfo::operator = (const imapInfo & mi) 00085 { 00086 // Avoid a = a. 00087 if (this == &mi) 00088 return *this; 00089 00090 count_ = mi.count_; 00091 recent_ = mi.recent_; 00092 unseen_ = mi.unseen_; 00093 uidValidity_ = mi.uidValidity_; 00094 uidNext_ = mi.uidNext_; 00095 flags_ = mi.flags_; 00096 permanentFlags_ = mi.permanentFlags_; 00097 readWrite_ = mi.readWrite_; 00098 countAvailable_ = mi.countAvailable_; 00099 recentAvailable_ = mi.recentAvailable_; 00100 unseenAvailable_ = mi.unseenAvailable_; 00101 uidValidityAvailable_ = mi.uidValidityAvailable_; 00102 uidNextAvailable_ = mi.uidNextAvailable_; 00103 flagsAvailable_ = mi.flagsAvailable_; 00104 permanentFlagsAvailable_ = mi.permanentFlagsAvailable_; 00105 readWriteAvailable_ = mi.readWriteAvailable_; 00106 00107 return *this; 00108 } 00109 00110 imapInfo::imapInfo (const QStringList & list):count_ (0), 00111 recent_ (0), 00112 unseen_ (0), 00113 uidValidity_ (0), 00114 uidNext_ (0), 00115 flags_ (0), 00116 permanentFlags_ (0), 00117 readWrite_ (false), 00118 countAvailable_ (false), 00119 recentAvailable_ (false), 00120 unseenAvailable_ (false), 00121 uidValidityAvailable_ (false), 00122 uidNextAvailable_ (false), 00123 flagsAvailable_ (false), 00124 permanentFlagsAvailable_ (false), readWriteAvailable_ (false) 00125 { 00126 for (QStringList::ConstIterator it (list.begin ()); it != list.end (); ++it) 00127 { 00128 QString line (*it); 00129 00130 line.truncate(line.length() - 2); 00131 QStringList tokens(line.split (' ', QString::SkipEmptyParts)); 00132 00133 kDebug(7116) <<"Processing:" << line; 00134 if (tokens[0] != "*") 00135 continue; 00136 00137 if (tokens[1] == "OK") 00138 { 00139 if (tokens[2] == "[UNSEEN") 00140 setUnseen (tokens[3].left (tokens[3].length () - 1).toULong ()); 00141 00142 else if (tokens[2] == "[UIDVALIDITY") 00143 setUidValidity (tokens[3].left (tokens[3].length () - 1).toULong ()); 00144 00145 else if (tokens[2] == "[UIDNEXT") 00146 setUidNext (tokens[3].left (tokens[3].length () - 1).toULong ()); 00147 00148 else if (tokens[2] == "[PERMANENTFLAGS") 00149 { 00150 int flagsStart = line.indexOf('('); 00151 int flagsEnd = line.indexOf(')'); 00152 00153 kDebug(7116) <<"Checking permFlags from" << flagsStart <<" to" << flagsEnd; 00154 if ((-1 != flagsStart) && (-1 != flagsEnd) && flagsStart < flagsEnd) 00155 setPermanentFlags (_flags (line.mid (flagsStart, flagsEnd).toLatin1())); 00156 00157 } 00158 else if (tokens[2] == "[READ-WRITE") 00159 { 00160 setReadWrite (true); 00161 } 00162 else if (tokens[2] == "[READ-ONLY") 00163 { 00164 setReadWrite (false); 00165 } 00166 else 00167 { 00168 kDebug(7116) <<"unknown token2:" << tokens[2]; 00169 } 00170 } 00171 else if (tokens[1] == "FLAGS") 00172 { 00173 int flagsStart = line.indexOf ('('); 00174 int flagsEnd = line.indexOf (')'); 00175 00176 if ((-1 != flagsStart) && (-1 != flagsEnd) && flagsStart < flagsEnd) 00177 setFlags (_flags (line.mid (flagsStart, flagsEnd).toLatin1() )); 00178 } 00179 else 00180 { 00181 if (tokens[2] == "EXISTS") 00182 setCount (tokens[1].toULong ()); 00183 00184 else if (tokens[2] == "RECENT") 00185 setRecent (tokens[1].toULong ()); 00186 00187 else 00188 kDebug(7116) <<"unknown token1/2:" << tokens[1] << tokens[2]; 00189 } 00190 } 00191 00192 } 00193 00194 ulong imapInfo::_flags( const QByteArray &inFlags ) 00195 { 00196 ulong flags = 0; 00197 parseString flagsString; 00198 flagsString.data = inFlags; 00199 if ( flagsString.isEmpty() ) { 00200 return flags; 00201 } 00202 00203 if ( flagsString[0] == '(' ) { 00204 flagsString.pos++; 00205 } 00206 00207 while( !flagsString.isEmpty () && flagsString[0] != ')' ) { 00208 QByteArray entry = imapParser::parseOneWord(flagsString).toUpper(); 00209 00210 if (entry.isEmpty ()) 00211 flagsString.clear(); 00212 else if (0 != entry.contains ("\\SEEN")) 00213 flags ^= Seen; 00214 else if (0 != entry.contains ("\\ANSWERED")) 00215 flags ^= Answered; 00216 else if (0 != entry.contains ("\\FLAGGED")) 00217 flags ^= Flagged; 00218 else if (0 != entry.contains ("\\DELETED")) 00219 flags ^= Deleted; 00220 else if (0 != entry.contains ("\\DRAFT")) 00221 flags ^= Draft; 00222 else if (0 != entry.contains ("\\RECENT")) 00223 flags ^= Recent; 00224 else if (0 != entry.contains ("\\*")) 00225 flags ^= User; 00226 00227 // non standard kmail flags 00228 else if ( entry.contains( "KMAILFORWARDED" ) || entry.contains( "$FORWARDED" ) ) 00229 flags = flags | Forwarded; 00230 else if ( entry.contains( "KMAILTODO" ) || entry.contains( "$TODO" ) ) 00231 flags = flags | Todo; 00232 else if ( entry.contains( "KMAILWATCHED" ) || entry.contains( "$WATCHED" ) ) 00233 flags = flags | Watched; 00234 else if ( entry.contains( "KMAILIGNORED" ) || entry.contains( "$IGNORED" ) ) 00235 flags = flags | Ignored; 00236 } 00237 00238 return flags; 00239 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:24:28 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:24:28 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.