• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

kioslave/imap4

mimeio.cpp

00001 /***************************************************************************
00002                           mimeio.cc  -  description
00003                              -------------------
00004     begin                : Wed Oct 25 2000
00005     copyright            : (C) 2000 by Sven Carstens
00006     email                : s.carstens@gmx.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "mimeio.h"
00019 #include <iostream>
00020 using namespace std;
00021 
00022 mimeIO::mimeIO ()
00023 {
00024   theCRLF = "\r\n";
00025   crlfLen = 2;
00026 }
00027 
00028 mimeIO::~mimeIO ()
00029 {
00030 }
00031 
00032 int mimeIO::inputLine (QByteArray & aLine)
00033 {
00034   char input;
00035 
00036   aLine = QByteArray();
00037   while (inputChar (input))
00038   {
00039     aLine += input;
00040     if (input == '\n')
00041       break;
00042   }
00043 //  cout << aLine.length() << " - " << aLine;
00044   return aLine.length ();
00045 }
00046 
00047 int mimeIO::outputLine (const QByteArray & aLine, int len)
00048 {
00049   int i;
00050 
00051   if (len == -1) {
00052     len = aLine.length();
00053   }
00054   int start = len;
00055   for (i = 0; i < start; i++)
00056     if (!outputChar (aLine[i]))
00057       break;
00058   return i;
00059 }
00060 
00061 int mimeIO::outputMimeLine (const QByteArray & inLine)
00062 {
00063   int retVal = 0;
00064   QByteArray aLine = inLine;
00065   int len = inLine.length();
00066 
00067   int theLF = aLine.lastIndexOf ('\n');
00068   if (theLF == len - 1 && theLF != -1)
00069   {
00070     //we have a trailing LF, now check for CR
00071     if (aLine[theLF - 1] == '\r')
00072       theLF--;
00073     //truncate the line
00074     aLine.truncate(theLF);
00075     len = theLF;
00076     theLF = -1;
00077   }
00078   //now truncate the line
00079   {
00080     int start, end, offset;
00081     start = 0;
00082     end = aLine.indexOf ('\n', start);
00083     while (end >= 0)
00084     {
00085       offset = 1;
00086       if (end && aLine[end - 1] == '\r')
00087       {
00088         offset++;
00089         end--;
00090       }
00091       outputLine (aLine.mid (start, end - start) + theCRLF, end - start + crlfLen);
00092       start = end + offset;
00093       end = aLine.indexOf ('\n', start);
00094     }
00095     outputLine (aLine.mid (start, len - start) + theCRLF, len - start + crlfLen);
00096   }
00097   return retVal;
00098 }
00099 
00100 int mimeIO::inputChar (char &aChar)
00101 {
00102   if (cin.eof ())
00103   {
00104 //    cout << "EOF" << endl;
00105     return 0;
00106   }
00107   cin.get (aChar);
00108   return 1;
00109 }
00110 
00111 int mimeIO::outputChar (char aChar)
00112 {
00113   cout << aChar;
00114   return 1;
00115 }
00116 
00117 // void mimeIO::setCRLF (const char *aCRLF)
00118 // {
00119 //   theCRLF = aCRLF;
00120 //   crlfLen = strlen(aCRLF);
00121 // }
00122 
00123 mimeIOQFile::mimeIOQFile (const QString & aName):
00124 mimeIO (),
00125 myFile (aName)
00126 {
00127   myFile.open (QIODevice::ReadOnly);
00128 }
00129 
00130 mimeIOQFile::~mimeIOQFile ()
00131 {
00132   myFile.close ();
00133 }
00134 
00135 int mimeIOQFile::outputLine (const QByteArray &, int)
00136 {
00137   return 0;
00138 }
00139 
00140 int mimeIOQFile::inputLine (QByteArray & data)
00141 {
00142   data.resize( 1024 );
00143   myFile.readLine (data.data(), 1024);
00144 
00145   return data.length ();
00146 }
00147 
00148 mimeIOQString::mimeIOQString ()
00149 {
00150 }
00151 
00152 mimeIOQString::~mimeIOQString ()
00153 {
00154 }
00155 
00156 int mimeIOQString::outputLine (const QByteArray & _str, int len)
00157 {
00158   if (len == -1) {
00159     len = _str.length();
00160   }
00161   theString += _str;
00162   return len;
00163 }
00164 
00165 int mimeIOQString::inputLine (QByteArray & _str)
00166 {
00167   if (theString.isEmpty ())
00168     return 0;
00169 
00170   int i = theString.indexOf ('\n');
00171 
00172   if (i == -1)
00173     return 0;
00174   _str = theString.left (i + 1).toLatin1 ();
00175   theString = theString.right (theString.length () - i - 1);
00176   return _str.length ();
00177 }

kioslave/imap4

Skip menu "kioslave/imap4"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal