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

kioslave/mbox

  • kioslave
  • mbox
mbox.cpp
1 /*
2  * This is a simple kioslave to handle mbox-files.
3  * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 #include "mbox.h"
20 
21 #include "readmbox.h"
22 #include "stat.h"
23 #include "urlinfo.h"
24 
25 #include <QString>
26 
27 #include <kdebug.h>
28 #include <klocale.h>
29 #include <kcomponentdata.h>
30 #include <kglobal.h>
31 #include <kurl.h>
32 #include <kio/global.h>
33 
34 #include <stdlib.h>
35 
36 #include "kdemacros.h"
37 
38 extern "C" { KDE_EXPORT int kdemain(int argc, char* argv[]); }
39 
40 int kdemain( int argc, char * argv[] )
41 {
42  KComponentData instance("kio_mbox", "kdelibs4");
43  (void) KGlobal::locale();
44 
45  if (argc != 4) {
46  fprintf(stderr, "Usage: kio_mbox protocol "
47  "domain-socket1 domain-socket2\n");
48  exit(-1);
49  }
50 
51  MBoxProtocol slave(argv[2], argv[3]);
52  slave.dispatchLoop();
53 
54  return 0;
55 }
56 
57 MBoxProtocol::MBoxProtocol( const QByteArray& arg1, const QByteArray& arg2 )
58  : KIO::SlaveBase( "mbox2", arg1, arg2 ),
59  m_errorState( true )
60 {
61 
62 }
63 
64 MBoxProtocol::~MBoxProtocol()
65 {
66 }
67 
68 void MBoxProtocol::get( const KUrl& url )
69 {
70  m_errorState = false;
71 
72  UrlInfo info( url, UrlInfo::message );
73  QString line;
74  QByteArray ba_line;
75 
76  if( info.type() == UrlInfo::invalid && !m_errorState )
77  {
78  error( KIO::ERR_DOES_NOT_EXIST, info.url() );
79  return;
80  }
81 
82  ReadMBox mbox( &info, this );
83 
84  while( !mbox.atEnd() && !m_errorState)
85  {
86  line = mbox.currentLine();
87  line += '\n';
88  ba_line = QByteArray( line.toUtf8() );
89  ba_line.truncate( ba_line.size() - 1 ); //Removing training '\0'
90  data( ba_line );
91  mbox.nextLine();
92  };
93 
94  if( !m_errorState )
95  {
96  data( QByteArray() );
97  finished();
98  }
99 }
100 
101 void MBoxProtocol::listDir( const KUrl& url )
102 {
103  m_errorState = false;
104 
105  KIO::UDSEntry entry;
106  UrlInfo info( url, UrlInfo::directory );
107  ReadMBox mbox( &info, this, hasMetaData( "onlynew" ), hasMetaData( "savetime" ) );
108 
109  if( m_errorState )
110  return;
111 
112  if( info.type() != UrlInfo::directory )
113  {
114  error( KIO::ERR_DOES_NOT_EXIST, info.url() );
115  return;
116  }
117 
118  while( !mbox.atEnd() && !m_errorState )
119  {
120  entry = Stat::stat( mbox, info );
121  if( mbox.inListing() )
122  listEntry( entry, false );
123  }
124 
125  listEntry( KIO::UDSEntry(), true );
126  finished();
127 }
128 
129 void MBoxProtocol::stat( const KUrl& url )
130 {
131  UrlInfo info( url );
132  if( info.type() == UrlInfo::invalid )
133  {
134  error( KIO::ERR_DOES_NOT_EXIST, url.path() );
135  return;
136  } else
137  {
138  statEntry( Stat::stat( info ) );
139  }
140  finished();
141 }
142 
143 void MBoxProtocol::mimetype( const KUrl& url )
144 {
145  m_errorState = false;
146 
147  UrlInfo info( url );
148 
149  if( m_errorState )
150  return;
151 
152  if( info.type() == UrlInfo::invalid )
153  error( KIO::ERR_DOES_NOT_EXIST, i18n( "Invalid URL" ) );
154  else
155  mimeType( info.mimetype() );
156  finished();
157 }
158 
159 void MBoxProtocol::emitError( int _errno, const QString& arg )
160 {
161  m_errorState = true;
162  error( _errno, arg );
163 }
164 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:25:32 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kioslave/mbox

Skip menu "kioslave/mbox"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List

kdepimlibs-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 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
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