You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
240 lines
7.1 KiB
240 lines
7.1 KiB
15 years ago
|
/**********************************************************************
|
||
|
*
|
||
4 years ago
|
* imapinfo.cpp - IMAP4rev1 SELECT / EXAMINE handler
|
||
17 years ago
|
* Copyright (C) 2000 Sven Carstens <s.carstens@gmx.de>
|
||
15 years ago
|
*
|
||
|
* This program is free software; you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation; either version 2 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
*
|
||
|
* Send comments and bug fixes to
|
||
|
*
|
||
|
*********************************************************************/
|
||
|
|
||
|
/*
|
||
|
References:
|
||
|
RFC 2060 - Internet Message Access Protocol - Version 4rev1 - December 1996
|
||
|
RFC 2192 - IMAP URL Scheme - September 1997
|
||
|
RFC 1731 - IMAP Authentication Mechanisms - December 1994
|
||
|
(Discusses KERBEROSv4, GSSAPI, and S/Key)
|
||
|
RFC 2195 - IMAP/POP AUTHorize Extension for Simple Challenge/Response
|
||
|
- September 1997 (CRAM-MD5 authentication method)
|
||
|
RFC 2104 - HMAC: Keyed-Hashing for Message Authentication - February 1997
|
||
|
|
||
|
Supported URLs:
|
||
|
imap://server/ - Prompt for user/pass, list all folders in home directory
|
||
|
imap://user:pass@server/ - Uses LOGIN to log in
|
||
|
imap://user;AUTH=method:pass@server/ - Uses AUTHENTICATE to log in
|
||
|
|
||
|
imap://server/folder/ - List messages in folder
|
||
|
*/
|
||
|
|
||
|
#include "imapinfo.h"
|
||
|
#include "imapparser.h"
|
||
|
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
imapInfo::imapInfo ():count_ (0),
|
||
|
recent_ (0),
|
||
|
unseen_ (0),
|
||
|
uidValidity_ (0),
|
||
|
uidNext_ (0),
|
||
|
flags_ (0),
|
||
|
permanentFlags_ (0),
|
||
|
readWrite_ (false),
|
||
|
countAvailable_ (false),
|
||
|
recentAvailable_ (false),
|
||
|
unseenAvailable_ (false),
|
||
|
uidValidityAvailable_ (false),
|
||
|
uidNextAvailable_ (false),
|
||
|
flagsAvailable_ (false),
|
||
|
permanentFlagsAvailable_ (false), readWriteAvailable_ (false)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
imapInfo::imapInfo (const imapInfo & mi):count_ (mi.count_),
|
||
|
recent_ (mi.recent_),
|
||
|
unseen_ (mi.unseen_),
|
||
|
uidValidity_ (mi.uidValidity_),
|
||
|
uidNext_ (mi.uidNext_),
|
||
|
flags_ (mi.flags_),
|
||
|
permanentFlags_ (mi.permanentFlags_),
|
||
|
readWrite_ (mi.readWrite_),
|
||
|
countAvailable_ (mi.countAvailable_),
|
||
|
recentAvailable_ (mi.recentAvailable_),
|
||
|
unseenAvailable_ (mi.unseenAvailable_),
|
||
|
uidValidityAvailable_ (mi.uidValidityAvailable_),
|
||
|
uidNextAvailable_ (mi.uidNextAvailable_),
|
||
|
flagsAvailable_ (mi.flagsAvailable_),
|
||
|
permanentFlagsAvailable_ (mi.permanentFlagsAvailable_),
|
||
|
readWriteAvailable_ (mi.readWriteAvailable_)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
imapInfo & imapInfo::operator = (const imapInfo & mi)
|
||
|
{
|
||
|
// Avoid a = a.
|
||
|
if (this == &mi)
|
||
|
return *this;
|
||
|
|
||
|
count_ = mi.count_;
|
||
|
recent_ = mi.recent_;
|
||
|
unseen_ = mi.unseen_;
|
||
|
uidValidity_ = mi.uidValidity_;
|
||
|
uidNext_ = mi.uidNext_;
|
||
|
flags_ = mi.flags_;
|
||
|
permanentFlags_ = mi.permanentFlags_;
|
||
|
readWrite_ = mi.readWrite_;
|
||
|
countAvailable_ = mi.countAvailable_;
|
||
|
recentAvailable_ = mi.recentAvailable_;
|
||
|
unseenAvailable_ = mi.unseenAvailable_;
|
||
|
uidValidityAvailable_ = mi.uidValidityAvailable_;
|
||
|
uidNextAvailable_ = mi.uidNextAvailable_;
|
||
|
flagsAvailable_ = mi.flagsAvailable_;
|
||
|
permanentFlagsAvailable_ = mi.permanentFlagsAvailable_;
|
||
|
readWriteAvailable_ = mi.readWriteAvailable_;
|
||
|
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
15 years ago
|
imapInfo::imapInfo (const TQStringList & list):count_ (0),
|
||
15 years ago
|
recent_ (0),
|
||
|
unseen_ (0),
|
||
|
uidValidity_ (0),
|
||
|
uidNext_ (0),
|
||
|
flags_ (0),
|
||
|
permanentFlags_ (0),
|
||
|
readWrite_ (false),
|
||
|
countAvailable_ (false),
|
||
|
recentAvailable_ (false),
|
||
|
unseenAvailable_ (false),
|
||
|
uidValidityAvailable_ (false),
|
||
|
uidNextAvailable_ (false),
|
||
|
flagsAvailable_ (false),
|
||
|
permanentFlagsAvailable_ (false), readWriteAvailable_ (false)
|
||
|
{
|
||
15 years ago
|
for (TQStringList::ConstIterator it (list.begin ()); it != list.end (); ++it)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString line (*it);
|
||
15 years ago
|
|
||
|
line.truncate(line.length() - 2);
|
||
15 years ago
|
TQStringList tokens(TQStringList::split (' ', line));
|
||
15 years ago
|
|
||
|
kdDebug(7116) << "Processing: " << line << endl;
|
||
|
if (tokens[0] != "*")
|
||
|
continue;
|
||
|
|
||
|
if (tokens[1] == "OK")
|
||
|
{
|
||
|
if (tokens[2] == "[UNSEEN")
|
||
|
setUnseen (tokens[3].left (tokens[3].length () - 1).toULong ());
|
||
|
|
||
|
else if (tokens[2] == "[UIDVALIDITY")
|
||
|
setUidValidity (tokens[3].left (tokens[3].length () - 1).toULong ());
|
||
|
|
||
|
else if (tokens[2] == "[UIDNEXT")
|
||
|
setUidNext (tokens[3].left (tokens[3].length () - 1).toULong ());
|
||
|
|
||
|
else if (tokens[2] == "[PERMANENTFLAGS")
|
||
|
{
|
||
13 years ago
|
int flagsStart = line.find('(');
|
||
|
int flagsEnd = line.find(')');
|
||
15 years ago
|
|
||
|
kdDebug(7116) << "Checking permFlags from " << flagsStart << " to " << flagsEnd << endl;
|
||
|
if ((-1 != flagsStart) && (-1 != flagsEnd) && flagsStart < flagsEnd)
|
||
|
setPermanentFlags (_flags (line.mid (flagsStart, flagsEnd).latin1()));
|
||
|
|
||
|
}
|
||
|
else if (tokens[2] == "[READ-WRITE")
|
||
|
{
|
||
|
setReadWrite (true);
|
||
|
}
|
||
|
else if (tokens[2] == "[READ-ONLY")
|
||
|
{
|
||
|
setReadWrite (false);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
kdDebug(7116) << "unknown token2: " << tokens[2] << endl;
|
||
|
}
|
||
|
}
|
||
|
else if (tokens[1] == "FLAGS")
|
||
|
{
|
||
13 years ago
|
int flagsStart = line.find ('(');
|
||
|
int flagsEnd = line.find (')');
|
||
15 years ago
|
|
||
|
if ((-1 != flagsStart) && (-1 != flagsEnd) && flagsStart < flagsEnd)
|
||
|
setFlags (_flags (line.mid (flagsStart, flagsEnd).latin1() ));
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (tokens[2] == "EXISTS")
|
||
|
setCount (tokens[1].toULong ());
|
||
|
|
||
|
else if (tokens[2] == "RECENT")
|
||
|
setRecent (tokens[1].toULong ());
|
||
|
|
||
|
else
|
||
|
kdDebug(7116) << "unknown token1/2: " << tokens[1] << " " << tokens[2] << endl;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
15 years ago
|
ulong imapInfo::_flags (const TQCString & inFlags)
|
||
15 years ago
|
{
|
||
|
ulong flags = 0;
|
||
|
parseString flagsString;
|
||
|
flagsString.data.duplicate(inFlags.data(), inFlags.length());
|
||
17 years ago
|
if ( flagsString.isEmpty() ) {
|
||
|
return flags;
|
||
|
}
|
||
15 years ago
|
|
||
|
if (flagsString[0] == '(')
|
||
|
flagsString.pos++;
|
||
|
|
||
|
while (!flagsString.isEmpty () && flagsString[0] != ')')
|
||
|
{
|
||
15 years ago
|
TQCString entry = imapParser::parseOneWordC(flagsString).upper();
|
||
15 years ago
|
|
||
|
if (entry.isEmpty ())
|
||
|
flagsString.clear();
|
||
13 years ago
|
else if (0 != entry.contains ("\\SEEN"))
|
||
15 years ago
|
flags ^= Seen;
|
||
13 years ago
|
else if (0 != entry.contains ("\\ANSWERED"))
|
||
15 years ago
|
flags ^= Answered;
|
||
13 years ago
|
else if (0 != entry.contains ("\\FLAGGED"))
|
||
15 years ago
|
flags ^= Flagged;
|
||
13 years ago
|
else if (0 != entry.contains ("\\DELETED"))
|
||
15 years ago
|
flags ^= Deleted;
|
||
13 years ago
|
else if (0 != entry.contains ("\\DRAFT"))
|
||
15 years ago
|
flags ^= Draft;
|
||
13 years ago
|
else if (0 != entry.contains ("\\RECENT"))
|
||
15 years ago
|
flags ^= Recent;
|
||
13 years ago
|
else if (0 != entry.contains ("\\*"))
|
||
15 years ago
|
flags ^= User;
|
||
|
|
||
|
// non standard kmail falgs
|
||
13 years ago
|
else if ( entry.contains( "KMAILFORWARDED" ) || entry.contains( "$FORWARDED" ) )
|
||
15 years ago
|
flags = flags | Forwarded;
|
||
13 years ago
|
else if ( entry.contains( "KMAILTODO" ) || entry.contains( "$TODO" ) )
|
||
15 years ago
|
flags = flags | Todo;
|
||
13 years ago
|
else if ( entry.contains( "KMAILWATCHED" ) || entry.contains( "$WATCHED" ) )
|
||
15 years ago
|
flags = flags | Watched;
|
||
13 years ago
|
else if ( entry.contains( "KMAILIGNORED" ) || entry.contains( "$IGNORED" ) )
|
||
15 years ago
|
flags = flags | Ignored;
|
||
|
}
|
||
|
|
||
|
return flags;
|
||
|
}
|