~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to libksieve/kmanagesieve/response.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
 
3
    Author: Volker Krause <volker.krause@kdab.com>
 
4
 
 
5
    This library is free software; you can redistribute it and/or modify it
 
6
    under the terms of the GNU Library General Public License as published by
 
7
    the Free Software Foundation; either version 2 of the License, or (at your
 
8
    option) any later version.
 
9
 
 
10
    This library is distributed in the hope that it will be useful, but WITHOUT
 
11
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
12
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
 
13
    License for more details.
 
14
 
 
15
    You should have received a copy of the GNU Library General Public License
 
16
    along with this library; see the file COPYING.LIB.  If not, write to the
 
17
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
18
    02110-1301, USA.
 
19
*/
 
20
 
 
21
#include "response.h"
 
22
#include <KDebug>
 
23
 
 
24
void KManageSieve::Response::clear()
 
25
{
 
26
  m_type = None;
 
27
  m_key.clear();
 
28
  m_value.clear();
 
29
  m_extra.clear();
 
30
  m_quantity = 0;
 
31
}
 
32
 
 
33
QByteArray KManageSieve::Response::action() const
 
34
{
 
35
  return m_key;
 
36
}
 
37
 
 
38
QByteArray KManageSieve::Response::extra() const
 
39
{
 
40
  return m_extra;
 
41
}
 
42
 
 
43
QByteArray KManageSieve::Response::key() const
 
44
{
 
45
  return m_key;
 
46
}
 
47
 
 
48
QByteArray KManageSieve::Response::value() const
 
49
{
 
50
  return m_value;
 
51
}
 
52
 
 
53
uint KManageSieve::Response::quantity() const
 
54
{
 
55
  return m_quantity;
 
56
}
 
57
 
 
58
KManageSieve::Response::Type KManageSieve::Response::type() const
 
59
{
 
60
  return m_type;
 
61
}
 
62
 
 
63
bool KManageSieve::Response::parseResponse(const QByteArray& line)
 
64
{
 
65
  clear();
 
66
 
 
67
  switch( line.at( 0 ) ) {
 
68
    case '{':
 
69
    {
 
70
      // expecting {quantity}
 
71
      int start = 0;
 
72
      int end = line.indexOf( "+}", start + 1 );
 
73
      // some older versions of Cyrus enclose the literal size just in { } instead of { +}
 
74
      if ( end == -1 )
 
75
        end = line.indexOf( '}', start + 1 );
 
76
 
 
77
      bool ok = false;
 
78
      m_type = Quantity;
 
79
      m_quantity = line.mid( start + 1, end - start - 1 ).toUInt( &ok );
 
80
      if (!ok) {
 
81
//         disconnect();
 
82
//         error(ERR_INTERNAL_SERVER, i18n("A protocol error occurred."));
 
83
        return false;
 
84
      }
 
85
 
 
86
      return true;
 
87
    }
 
88
    case '"':
 
89
      // expecting "key" "value" pairs
 
90
      m_type = KeyValuePair;
 
91
      break;
 
92
    default:
 
93
      // expecting single string
 
94
      m_type = Action;
 
95
      m_key = line;
 
96
      return true;
 
97
  }
 
98
 
 
99
  int start = 0;
 
100
  int end = line.indexOf( '"', start + 1 );
 
101
  if ( end == -1 ) {
 
102
    kDebug() << "Invalid protocol in:" << line;
 
103
    m_key = line.right( line.length() - start );
 
104
    return true;
 
105
  }
 
106
  m_key = line.mid( start + 1, end - start - 1 );
 
107
 
 
108
  start = line.indexOf( '"', end + 1 );
 
109
  if (start == -1) {
 
110
    if ( line.length() > end )
 
111
      // skip " and space
 
112
      m_extra = line.right( line.length() - end - 2 );
 
113
    return true;
 
114
  }
 
115
 
 
116
  end = line.indexOf( '"', start + 1 );
 
117
  if ( end == -1 ) {
 
118
    kDebug() << "Invalid protocol in:" << line;
 
119
    m_value = line.right( line.length() - start );
 
120
    return true;
 
121
  }
 
122
 
 
123
  m_value = line.mid( start + 1, end - start - 1 );
 
124
  return true;
 
125
}
 
126
 
 
127
KManageSieve::Response::Result KManageSieve::Response::operationResult() const
 
128
{
 
129
  if ( m_type == Action ) {
 
130
    const QByteArray response = m_key.left( 2 );
 
131
    if ( response == "OK" ) {
 
132
      return Ok;
 
133
    } else if ( response == "NO" ) {
 
134
      return No;
 
135
    } else if ( response == "BY"/*E*/ ) {
 
136
      return Bye;
 
137
    }
 
138
  }
 
139
  return Other;
 
140
}
 
141
 
 
142
bool KManageSieve::Response::operationSuccessful() const
 
143
{
 
144
  return operationResult() == Ok;
 
145
}