~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to kioslave/smtp/capabilities.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ana Beatriz Guerrero Lopez
  • Date: 2009-04-05 05:22:13 UTC
  • mfrom: (0.4.2 experimental) (0.2.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 235.
  • Revision ID: james.westby@ubuntu.com-20090405052213-39thr4l6p2ss07uj
Tags: 4:4.2.2-1
* New upstream release:
  - khtml fixes. (Closes: #290285, #359680)
  - Default konsole sessions can be deleted. (Closes: #286342)
  - Tag widget uses standard application palette. (Closes: #444800)
  - ... and surely many more but we have lost track...

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  -*- c++ -*-
2
 
    capabilities.cc
3
 
 
4
 
    This file is part of kio_smtp, the KDE SMTP kioslave.
5
 
    Copyright (c) 2003 Marc Mutz <mutz@kde.org>
6
 
 
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.
10
 
 
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.
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
 
    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
29
 
    your version.
30
 
*/
31
 
 
32
 
#include <config.h>
33
 
 
34
 
#include "capabilities.h"
35
 
 
36
 
#include "response.h"
37
 
 
38
 
#include <qstrlist.h>
39
 
 
40
 
namespace KioSMTP {
41
 
 
42
 
  Capabilities Capabilities::fromResponse( const Response & ehlo ) {
43
 
    Capabilities c;
44
 
 
45
 
    // first, check whether the response was valid and indicates success:
46
 
    if ( !ehlo.isOk()
47
 
         || ehlo.code() / 10 != 25 // ### restrict to 250 only?
48
 
         || ehlo.lines().empty() )
49
 
      return c;
50
 
 
51
 
    QCStringList l = ehlo.lines();
52
 
 
53
 
    for ( QCStringList::const_iterator it = ++l.begin() ; it != l.end() ; ++it )
54
 
      c.add( *it );
55
 
 
56
 
    return c;
57
 
  }
58
 
 
59
 
  void Capabilities::add( const QString & cap, bool replace ) {
60
 
    QStringList tokens = QStringList::split( ' ', cap.upper() );
61
 
    if ( tokens.empty() )
62
 
      return;
63
 
    QString name = tokens.front(); tokens.pop_front();
64
 
    add( name, tokens, replace );
65
 
  }
66
 
 
67
 
  void Capabilities::add( const QString & name, const QStringList & args, bool replace ) {
68
 
    if ( replace )
69
 
      mCapabilities[name] = args;
70
 
    else
71
 
      mCapabilities[name] += args;
72
 
  }
73
 
 
74
 
  QString Capabilities::asMetaDataString() const {
75
 
    QString result;
76
 
    for ( QMap<QString,QStringList>::const_iterator it = mCapabilities.begin() ; it != mCapabilities.end() ; ++it ) {
77
 
      result += it.key();
78
 
      if ( !it.data().empty() )
79
 
        result += ' ' + it.data().join( " " );
80
 
      result += '\n';
81
 
    }
82
 
    return result;
83
 
  }
84
 
 
85
 
  QString Capabilities::authMethodMetaData() const {
86
 
    QStringList sl = saslMethodsQSL();
87
 
    QString result;
88
 
    for ( QStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it )
89
 
      result += "SASL/" + *it + '\n';
90
 
    return result;
91
 
  }
92
 
 
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() );
98
 
    return result;
99
 
  }
100
 
 
101
 
  QString Capabilities::createSpecialResponse( bool tls ) const {
102
 
    QStringList result;
103
 
    if ( tls )
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" ) ) {
111
 
      bool ok = false;
112
 
      unsigned int size = mCapabilities["SIZE"].front().toUInt( &ok );
113
 
      if ( ok && !size )
114
 
        result.push_back( "SIZE=*" ); // any size
115
 
      else if ( ok )
116
 
        result.push_back( "SIZE=" + QString::number( size ) ); // fixed max
117
 
      else
118
 
        result.push_back( "SIZE" ); // indetermined
119
 
    }
120
 
    return result.join( " " );
121
 
  }
122
 
 
123
 
  QStringList Capabilities::saslMethodsQSL() const {
124
 
    QStringList result;
125
 
    for ( QMap<QString,QStringList>::const_iterator it = mCapabilities.begin() ; it != mCapabilities.end() ; ++it ) {
126
 
      if ( it.key() == "AUTH" )
127
 
        result += it.data();
128
 
      else if ( it.key().startsWith( "AUTH=" ) ) {
129
 
        result.push_back( it.key().mid( qstrlen("AUTH=") ) );
130
 
        result += it.data();
131
 
      }
132
 
    }
133
 
    result.sort();
134
 
    QStringList::iterator it = result.begin();
135
 
    for (QStringList::iterator ot = it++; it != result.end(); ot = it++)
136
 
        if (*ot == *it) result.remove(ot);
137
 
    return result;
138
 
  }
139
 
 
140
 
 
141
 
 
142
 
} // namespace KioSMTP
143