4
This file is part of kio_smtp, the KDE SMTP kioslave.
5
Copyright (c) 2003 Marc Mutz <mutz@kde.org>
7
This program is free software; you can redistribute it and/or modify it
8
under the terms of the GNU General Public License, version 2, as
9
published by the Free Software Foundation.
11
This program is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
General Public License for more details.
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
20
In addition, as a special exception, the copyright holders give
21
permission to link the code of this program with any edition of
22
the Qt library by Trolltech AS, Norway (or with modified versions
23
of Qt that use the same license as Qt), and distribute linked
24
combinations including the two. You must obey the GNU General
25
Public License in all respects for all of the code used other than
26
Qt. If you modify this file, you may extend this exception to
27
your version of the file, but you are not obligated to do so. If
28
you do not wish to do so, delete this exception statement from
34
#include "capabilities.h"
42
Capabilities Capabilities::fromResponse( const Response & ehlo ) {
45
// first, check whether the response was valid and indicates success:
47
|| ehlo.code() / 10 != 25 // ### restrict to 250 only?
48
|| ehlo.lines().empty() )
51
QCStringList l = ehlo.lines();
53
for ( QCStringList::const_iterator it = ++l.begin() ; it != l.end() ; ++it )
59
void Capabilities::add( const QString & cap, bool replace ) {
60
QStringList tokens = QStringList::split( ' ', cap.upper() );
63
QString name = tokens.front(); tokens.pop_front();
64
add( name, tokens, replace );
67
void Capabilities::add( const QString & name, const QStringList & args, bool replace ) {
69
mCapabilities[name] = args;
71
mCapabilities[name] += args;
74
QString Capabilities::asMetaDataString() const {
76
for ( QMap<QString,QStringList>::const_iterator it = mCapabilities.begin() ; it != mCapabilities.end() ; ++it ) {
78
if ( !it.data().empty() )
79
result += ' ' + it.data().join( " " );
85
QString Capabilities::authMethodMetaData() const {
86
QStringList sl = saslMethodsQSL();
88
for ( QStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it )
89
result += "SASL/" + *it + '\n';
93
QStrIList Capabilities::saslMethods() const {
94
QStrIList result( true ); // deep copies to be safe
95
QStringList sl = saslMethodsQSL();
96
for ( QStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it )
97
result.append( (*it).latin1() );
101
QString Capabilities::createSpecialResponse( bool tls ) const {
104
result.push_back( "STARTTLS" );
105
result += saslMethodsQSL();
106
if ( have( "PIPELINING" ) )
107
result.push_back( "PIPELINING" );
108
if ( have( "8BITMIME" ) )
109
result.push_back( "8BITMIME" );
110
if ( have( "SIZE" ) ) {
112
unsigned int size = mCapabilities["SIZE"].front().toUInt( &ok );
114
result.push_back( "SIZE=*" ); // any size
116
result.push_back( "SIZE=" + QString::number( size ) ); // fixed max
118
result.push_back( "SIZE" ); // indetermined
120
return result.join( " " );
123
QStringList Capabilities::saslMethodsQSL() const {
125
for ( QMap<QString,QStringList>::const_iterator it = mCapabilities.begin() ; it != mCapabilities.end() ; ++it ) {
126
if ( it.key() == "AUTH" )
128
else if ( it.key().startsWith( "AUTH=" ) ) {
129
result.push_back( it.key().mid( qstrlen("AUTH=") ) );
134
QStringList::iterator it = result.begin();
135
for (QStringList::iterator ot = it++; it != result.end(); ot = it++)
136
if (*ot == *it) result.remove(ot);
142
} // namespace KioSMTP