• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 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 <klocalizedstring.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
38extern "C" { KDE_EXPORT int kdemain(int argc, char* argv[]); }
39
40int 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
57MBoxProtocol::MBoxProtocol( const QByteArray& arg1, const QByteArray& arg2 )
58 : KIO::SlaveBase( "mbox2", arg1, arg2 ),
59 m_errorState( true )
60{
61}
62
63MBoxProtocol::~MBoxProtocol()
64{
65}
66
67void MBoxProtocol::get( const KUrl& url )
68{
69 m_errorState = false;
70
71 UrlInfo info( url, UrlInfo::message );
72 QString line;
73 QByteArray ba_line;
74
75 if( info.type() == UrlInfo::invalid && !m_errorState ) {
76 error( KIO::ERR_DOES_NOT_EXIST, info.url() );
77 return;
78 }
79
80 ReadMBox mbox( &info, this );
81
82 while( !mbox.atEnd() && !m_errorState) {
83 line = mbox.currentLine();
84 line += '\n';
85 ba_line = QByteArray( line.toUtf8() );
86 ba_line.truncate( ba_line.size() - 1 ); //Removing training '\0'
87 data( ba_line );
88 mbox.nextLine();
89 };
90
91 if( !m_errorState ) {
92 data( QByteArray() );
93 finished();
94 }
95}
96
97void MBoxProtocol::listDir( const KUrl& url )
98{
99 m_errorState = false;
100
101 KIO::UDSEntry entry;
102 UrlInfo info( url, UrlInfo::directory );
103 ReadMBox mbox( &info, this, hasMetaData( "onlynew" ), hasMetaData( "savetime" ) );
104
105 if( m_errorState ) {
106 return;
107 }
108
109 if( info.type() != UrlInfo::directory ) {
110 error( KIO::ERR_DOES_NOT_EXIST, info.url() );
111 return;
112 }
113
114 while( !mbox.atEnd() && !m_errorState ) {
115 entry = Stat::stat( mbox, info );
116 if( mbox.inListing() ) {
117 listEntry( entry, false );
118 }
119 }
120
121 listEntry( KIO::UDSEntry(), true );
122 finished();
123}
124
125void MBoxProtocol::stat( const KUrl& url )
126{
127 UrlInfo info( url );
128 if( info.type() == UrlInfo::invalid ) {
129 error( KIO::ERR_DOES_NOT_EXIST, url.path() );
130 return;
131 } else {
132 statEntry( Stat::stat( info ) );
133 }
134 finished();
135}
136
137void MBoxProtocol::mimetype( const KUrl& url )
138{
139 m_errorState = false;
140
141 UrlInfo info( url );
142
143 if( m_errorState ) {
144 return;
145 }
146
147 if( info.type() == UrlInfo::invalid ) {
148 error( KIO::ERR_DOES_NOT_EXIST, i18n( "Invalid URL" ) );
149 } else {
150 mimeType( info.mimetype() );
151 }
152 finished();
153}
154
155void MBoxProtocol::emitError( int _errno, const QString& arg )
156{
157 m_errorState = true;
158 error( _errno, arg );
159}
160
MBoxProtocol
This class is the main class and implements all function which can be called through the user.
Definition mbox.h:34
MBoxProtocol::get
virtual void get(const KUrl &url)
This functions is used when an user or a program wants to get a file from a mbox-file.
Definition mbox.cpp:67
MBoxProtocol::listDir
virtual void listDir(const KUrl &url)
This functions gives a listing back.
Definition mbox.cpp:97
MBoxProtocol::stat
virtual void stat(const KUrl &url)
This functions gives general properties about a mbox-file, or mbox-email back.
Definition mbox.cpp:125
MBoxProtocol::MBoxProtocol
MBoxProtocol(const QByteArray &, const QByteArray &)
Constructor, for the parameters, See KIO::SlaveBase.
Definition mbox.cpp:57
MBoxProtocol::emitError
void emitError(int _errno, const QString &arg)
Through this functions, other class which have an instance to this class (classes which are part of k...
Definition mbox.cpp:155
MBoxProtocol::~MBoxProtocol
virtual ~MBoxProtocol()
Empty destructor.
Definition mbox.cpp:63
MBoxProtocol::mimetype
virtual void mimetype(const KUrl &url)
This functions determinate the mimetype of a given mbox-file or mbox-email.
Definition mbox.cpp:137
ReadMBox
This class handels reading from a mbox-file.
Definition readmbox.h:39
ReadMBox::nextLine
bool nextLine()
This function reads the next line.
Definition readmbox.cpp:76
ReadMBox::currentLine
QString currentLine() const
This functions return the current line.
Definition readmbox.cpp:66
ReadMBox::inListing
bool inListing() const
Return true if the message is a new message, or all messages are listed.
Definition readmbox.cpp:157
ReadMBox::atEnd
bool atEnd() const
Returns true if the cursor is at EOF.
Definition readmbox.cpp:149
Stat::stat
static KIO::UDSEntry stat(const UrlInfo &info)
This functions gives information with a given UrlInfo.
Definition stat.cpp:29
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 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.14.10 API Reference

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