• 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
mimeio.cpp
1 /***************************************************************************
2  mimeio.cc - description
3  -------------------
4  begin : Wed Oct 25 2000
5  copyright : (C) 2000 by Sven Carstens
6  email : s.carstens@gmx.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "mimeio.h"
19 #include <iostream>
20 using namespace std;
21 
22 mimeIO::mimeIO ()
23 {
24  theCRLF = "\r\n";
25  crlfLen = 2;
26 }
27 
28 mimeIO::~mimeIO ()
29 {
30 }
31 
32 int mimeIO::inputLine (QByteArray & aLine)
33 {
34  char input;
35 
36  aLine = QByteArray();
37  while ( inputChar( input ) ) {
38  aLine += input;
39  if ( input == '\n' ) {
40  break;
41  }
42  }
43 // cout << aLine.length() << " - " << aLine;
44  return aLine.length();
45 }
46 
47 int mimeIO::outputLine (const QByteArray & aLine, int len)
48 {
49  int i;
50 
51  if ( len == -1 ) {
52  len = aLine.length();
53  }
54  int start = len;
55  for ( i = 0; i < start; ++i ) {
56  if ( !outputChar( aLine[i] ) ) {
57  break;
58  }
59  }
60  return i;
61 }
62 
63 int mimeIO::outputMimeLine (const QByteArray & inLine)
64 {
65  int retVal = 0;
66  QByteArray aLine = inLine;
67  int len = inLine.length();
68 
69  int theLF = aLine.lastIndexOf( '\n' );
70  if ( theLF == len - 1 && theLF != -1 ) {
71  //we have a trailing LF, now check for CR
72  if ( aLine[theLF - 1] == '\r' ) {
73  theLF--;
74  }
75  //truncate the line
76  aLine.truncate( theLF );
77  len = theLF;
78  theLF = -1;
79  }
80  //now truncate the line
81  {
82  int start, end, offset;
83  start = 0;
84  end = aLine.indexOf( '\n', start );
85  while ( end >= 0 ) {
86  offset = 1;
87  if ( end && aLine[end - 1] == '\r' ) {
88  offset++;
89  end--;
90  }
91  outputLine( aLine.mid( start, end - start ) + theCRLF, end - start + crlfLen );
92  start = end + offset;
93  end = aLine.indexOf( '\n', start );
94  }
95  outputLine( aLine.mid( start, len - start ) + theCRLF, len - start + crlfLen );
96  }
97  return retVal;
98 }
99 
100 int mimeIO::inputChar (char &aChar)
101 {
102  if ( cin.eof() ) {
103 // cout << "EOF" << endl;
104  return 0;
105  }
106  cin.get( aChar );
107  return 1;
108 }
109 
110 int mimeIO::outputChar (char aChar)
111 {
112  cout << aChar;
113  return 1;
114 }
115 
116 // void mimeIO::setCRLF (const char *aCRLF)
117 // {
118 // theCRLF = aCRLF;
119 // crlfLen = strlen(aCRLF);
120 // }
121 
122 mimeIOQFile::mimeIOQFile (const QString & aName):
123 mimeIO (),
124 myFile (aName)
125 {
126  myFile.open( QIODevice::ReadOnly );
127 }
128 
129 mimeIOQFile::~mimeIOQFile ()
130 {
131  myFile.close();
132 }
133 
134 int mimeIOQFile::outputLine (const QByteArray &, int)
135 {
136  return 0;
137 }
138 
139 int mimeIOQFile::inputLine (QByteArray & data)
140 {
141  data.resize( 1024 );
142  myFile.readLine( data.data(), 1024 );
143 
144  return data.length();
145 }
146 
147 mimeIOQString::mimeIOQString ()
148 {
149 }
150 
151 mimeIOQString::~mimeIOQString ()
152 {
153 }
154 
155 int mimeIOQString::outputLine (const QByteArray & _str, int len)
156 {
157  if ( len == -1 ) {
158  len = _str.length();
159  }
160  theString += _str;
161  return len;
162 }
163 
164 int mimeIOQString::inputLine (QByteArray & _str)
165 {
166  if ( theString.isEmpty() ) {
167  return 0;
168  }
169 
170  int i = theString.indexOf( '\n' );
171 
172  if ( i == -1 ) {
173  return 0;
174  }
175  _str = theString.left( i + 1 ).toLatin1();
176  theString = theString.right( theString.length() - i - 1 );
177  return _str.length();
178 }
QByteArray
mimeIO
Definition: mimeio.h:28
QByteArray::lastIndexOf
int lastIndexOf(char ch, int from) const
QByteArray::length
int length() const
QByteArray::resize
void resize(int size)
QByteArray::indexOf
int indexOf(char ch, int from) const
QByteArray::right
QByteArray right(int len) const
QByteArray::truncate
void truncate(int pos)
QString
QByteArray::mid
QByteArray mid(int pos, int len) const
QByteArray::left
QByteArray left(int len) const
QByteArray::data
char * data()
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