• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

kioslave/imap4

  • sources
  • kde-4.14
  • kdepimlibs
  • kioslave
  • imap4
imapinfo.cpp
1 /**********************************************************************
2  *
3  * imapinfo.cc - IMAP4rev1 SELECT / EXAMINE handler
4  * Copyright (C) 2000 Sven Carstens <s.carstens@gmx.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * Send comments and bug fixes to
21  *
22  *********************************************************************/
23 
24 /*
25  References:
26  RFC 2060 - Internet Message Access Protocol - Version 4rev1 - December 1996
27  RFC 2192 - IMAP URL Scheme - September 1997
28  RFC 1731 - IMAP Authentication Mechanisms - December 1994
29  (Discusses KERBEROSv4, GSSAPI, and S/Key)
30  RFC 2195 - IMAP/POP AUTHorize Extension for Simple Challenge/Response
31  - September 1997 (CRAM-MD5 authentication method)
32  RFC 2104 - HMAC: Keyed-Hashing for Message Authentication - February 1997
33 
34  Supported URLs:
35  imap://server/ - Prompt for user/pass, list all folders in home directory
36  imap://user:pass@server/ - Uses LOGIN to log in
37  imap://user;AUTH=method:pass@server/ - Uses AUTHENTICATE to log in
38 
39  imap://server/folder/ - List messages in folder
40  */
41 
42 #include "imapinfo.h"
43 #include "imapparser.h"
44 
45 #include <kdebug.h>
46 
47 imapInfo::imapInfo ():count_ (0),
48 recent_ (0),
49 unseen_ (0),
50 uidValidity_ (0),
51 uidNext_ (0),
52 flags_ (0),
53 permanentFlags_ (0),
54 readWrite_ (false),
55 countAvailable_ (false),
56 recentAvailable_ (false),
57 unseenAvailable_ (false),
58 uidValidityAvailable_ (false),
59 uidNextAvailable_ (false),
60 flagsAvailable_ (false),
61 permanentFlagsAvailable_ (false), readWriteAvailable_ (false)
62 {
63 }
64 
65 imapInfo::imapInfo (const imapInfo & mi):count_ (mi.count_),
66 recent_ (mi.recent_),
67 unseen_ (mi.unseen_),
68 uidValidity_ (mi.uidValidity_),
69 uidNext_ (mi.uidNext_),
70 flags_ (mi.flags_),
71 permanentFlags_ (mi.permanentFlags_),
72 readWrite_ (mi.readWrite_),
73 countAvailable_ (mi.countAvailable_),
74 recentAvailable_ (mi.recentAvailable_),
75 unseenAvailable_ (mi.unseenAvailable_),
76 uidValidityAvailable_ (mi.uidValidityAvailable_),
77 uidNextAvailable_ (mi.uidNextAvailable_),
78 flagsAvailable_ (mi.flagsAvailable_),
79 permanentFlagsAvailable_ (mi.permanentFlagsAvailable_),
80 readWriteAvailable_ (mi.readWriteAvailable_)
81 {
82 }
83 
84 imapInfo & imapInfo::operator = (const imapInfo & mi)
85 {
86  // Avoid a = a.
87  if ( this == &mi ) {
88  return *this;
89  }
90 
91  count_ = mi.count_;
92  recent_ = mi.recent_;
93  unseen_ = mi.unseen_;
94  uidValidity_ = mi.uidValidity_;
95  uidNext_ = mi.uidNext_;
96  flags_ = mi.flags_;
97  permanentFlags_ = mi.permanentFlags_;
98  readWrite_ = mi.readWrite_;
99  countAvailable_ = mi.countAvailable_;
100  recentAvailable_ = mi.recentAvailable_;
101  unseenAvailable_ = mi.unseenAvailable_;
102  uidValidityAvailable_ = mi.uidValidityAvailable_;
103  uidNextAvailable_ = mi.uidNextAvailable_;
104  flagsAvailable_ = mi.flagsAvailable_;
105  permanentFlagsAvailable_ = mi.permanentFlagsAvailable_;
106  readWriteAvailable_ = mi.readWriteAvailable_;
107 
108  return *this;
109 }
110 
111 imapInfo::imapInfo (const QStringList & list):count_ (0),
112 recent_ (0),
113 unseen_ (0),
114 uidValidity_ (0),
115 uidNext_ (0),
116 flags_ (0),
117 permanentFlags_ (0),
118 readWrite_ (false),
119 countAvailable_ (false),
120 recentAvailable_ (false),
121 unseenAvailable_ (false),
122 uidValidityAvailable_ (false),
123 uidNextAvailable_ (false),
124 flagsAvailable_ (false),
125 permanentFlagsAvailable_ (false), readWriteAvailable_ (false)
126 {
127  for ( QStringList::ConstIterator it( list.begin() ); it != list.end(); ++it ) {
128  QString line( *it );
129 
130  line.truncate( line.length() - 2 );
131  QStringList tokens( line.split( ' ', QString::SkipEmptyParts ) );
132 
133  kDebug( 7116 ) << "Processing:" << line;
134  if ( tokens[0] != "*" ) {
135  continue;
136  }
137 
138  if ( tokens[1] == "OK" ) {
139  if ( tokens[2] == "[UNSEEN" ) {
140  setUnseen( tokens[3].left( tokens[3].length() - 1 ).toULong() );
141  } else if ( tokens[2] == "[UIDVALIDITY" ) {
142  setUidValidity( tokens[3].left( tokens[3].length() - 1 ).toULong() );
143  } else if ( tokens[2] == "[UIDNEXT" ) {
144  setUidNext( tokens[3].left( tokens[3].length() - 1 ).toULong() );
145  } else if ( tokens[2] == "[PERMANENTFLAGS" ) {
146  int flagsStart = line.indexOf( '(' );
147  int flagsEnd = line.indexOf( ')' );
148 
149  kDebug( 7116 ) << "Checking permFlags from" << flagsStart << " to" << flagsEnd;
150  if ( ( -1 != flagsStart ) && ( -1 != flagsEnd ) && flagsStart < flagsEnd ) {
151  setPermanentFlags( _flags( line.mid( flagsStart, flagsEnd ).toLatin1() ) );
152  }
153  } else if ( tokens[2] == "[READ-WRITE" ) {
154  setReadWrite( true );
155  } else if ( tokens[2] == "[READ-ONLY" ) {
156  setReadWrite( false );
157  } else {
158  kDebug( 7116 ) << "unknown token2:" << tokens[2];
159  }
160  } else if ( tokens[1] == "FLAGS" ) {
161  int flagsStart = line.indexOf( '(' );
162  int flagsEnd = line.indexOf( ')' );
163 
164  if ( ( -1 != flagsStart ) && ( -1 != flagsEnd ) && flagsStart < flagsEnd ) {
165  setFlags( _flags( line.mid( flagsStart, flagsEnd ).toLatin1() ) );
166  }
167  } else {
168  if ( tokens[2] == "EXISTS" ) {
169  setCount( tokens[1].toULong() );
170  } else if ( tokens[2] == "RECENT" ) {
171  setRecent( tokens[1].toULong() );
172  } else {
173  kDebug( 7116 ) << "unknown token1/2:" << tokens[1] << tokens[2];
174  }
175  }
176  }
177 }
178 
179 ulong imapInfo::_flags( const QByteArray &inFlags )
180 {
181  ulong flags = 0;
182  parseString flagsString;
183  flagsString.data = inFlags;
184  if ( flagsString.isEmpty() ) {
185  return flags;
186  }
187 
188  if ( flagsString[0] == '(' ) {
189  flagsString.pos++;
190  }
191 
192  while ( !flagsString.isEmpty() && flagsString[0] != ')' ) {
193  QByteArray entry = imapParser::parseOneWord( flagsString ).toUpper();
194 
195  if ( entry.isEmpty() ) {
196  flagsString.clear();
197  } else if ( 0 != entry.contains( "\\SEEN" ) ) {
198  flags ^= Seen;
199  } else if ( 0 != entry.contains( "\\ANSWERED" ) ) {
200  flags ^= Answered;
201  } else if ( 0 != entry.contains( "\\FLAGGED" ) ) {
202  flags ^= Flagged;
203  } else if ( 0 != entry.contains( "\\DELETED" ) ) {
204  flags ^= Deleted;
205  } else if ( 0 != entry.contains( "\\DRAFT" ) ) {
206  flags ^= Draft;
207  } else if ( 0 != entry.contains( "\\RECENT" ) ) {
208  flags ^= Recent;
209  } else if ( 0 != entry.contains( "\\*" ) ) {
210  flags ^= User;
211 
212  // non standard kmail flags
213  } else if ( entry.contains( "KMAILFORWARDED" ) || entry.contains( "$FORWARDED" ) ) {
214  flags = flags | Forwarded;
215  } else if ( entry.contains( "KMAILTODO" ) || entry.contains( "$TODO" ) ) {
216  flags = flags | Todo;
217  } else if ( entry.contains( "KMAILWATCHED" ) || entry.contains( "$WATCHED" ) ) {
218  flags = flags | Watched;
219  } else if ( entry.contains( "KMAILIGNORED" ) || entry.contains( "$IGNORED" ) ) {
220  flags = flags | Ignored;
221  }
222  }
223  return flags;
224 }
QByteArray
QByteArray::toUpper
QByteArray toUpper() const
QByteArray::isEmpty
bool isEmpty() const
parseString
a string used during parsing the string allows you to move the effective start of the string using st...
Definition: imapparser.h:51
QString
QStringList
QList::end
iterator end()
QList::ConstIterator
typedef ConstIterator
QByteArray::contains
bool contains(char ch) const
QList::begin
iterator begin()
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kioslave/imap4

Skip menu "kioslave/imap4"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal