• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.1 API Reference
  • KDE Home
  • Contact Us
 

kioslave/imap4

  • 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  {
39  aLine += input;
40  if (input == '\n')
41  break;
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  {
72  //we have a trailing LF, now check for CR
73  if (aLine[theLF - 1] == '\r')
74  theLF--;
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  {
87  offset = 1;
88  if (end && aLine[end - 1] == '\r')
89  {
90  offset++;
91  end--;
92  }
93  outputLine (aLine.mid (start, end - start) + theCRLF, end - start + crlfLen);
94  start = end + offset;
95  end = aLine.indexOf ('\n', start);
96  }
97  outputLine (aLine.mid (start, len - start) + theCRLF, len - start + crlfLen);
98  }
99  return retVal;
100 }
101 
102 int mimeIO::inputChar (char &aChar)
103 {
104  if (cin.eof ())
105  {
106 // cout << "EOF" << endl;
107  return 0;
108  }
109  cin.get (aChar);
110  return 1;
111 }
112 
113 int mimeIO::outputChar (char aChar)
114 {
115  cout << aChar;
116  return 1;
117 }
118 
119 // void mimeIO::setCRLF (const char *aCRLF)
120 // {
121 // theCRLF = aCRLF;
122 // crlfLen = strlen(aCRLF);
123 // }
124 
125 mimeIOQFile::mimeIOQFile (const QString & aName):
126 mimeIO (),
127 myFile (aName)
128 {
129  myFile.open (QIODevice::ReadOnly);
130 }
131 
132 mimeIOQFile::~mimeIOQFile ()
133 {
134  myFile.close ();
135 }
136 
137 int mimeIOQFile::outputLine (const QByteArray &, int)
138 {
139  return 0;
140 }
141 
142 int mimeIOQFile::inputLine (QByteArray & data)
143 {
144  data.resize( 1024 );
145  myFile.readLine (data.data(), 1024);
146 
147  return data.length ();
148 }
149 
150 mimeIOQString::mimeIOQString ()
151 {
152 }
153 
154 mimeIOQString::~mimeIOQString ()
155 {
156 }
157 
158 int mimeIOQString::outputLine (const QByteArray & _str, int len)
159 {
160  if (len == -1) {
161  len = _str.length();
162  }
163  theString += _str;
164  return len;
165 }
166 
167 int mimeIOQString::inputLine (QByteArray & _str)
168 {
169  if (theString.isEmpty ())
170  return 0;
171 
172  int i = theString.indexOf ('\n');
173 
174  if (i == -1)
175  return 0;
176  _str = theString.left (i + 1).toLatin1 ();
177  theString = theString.right (theString.length () - i - 1);
178  return _str.length ();
179 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Sep 24 2012 09:02:51 by doxygen 1.8.1.1 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-4.9.1 API Reference

Skip menu "kdepimlibs-4.9.1 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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