summaryrefslogtreecommitdiffstats
path: root/tdeioslaves/mbox
diff options
context:
space:
mode:
Diffstat (limited to 'tdeioslaves/mbox')
-rw-r--r--tdeioslaves/mbox/AUTHORS1
-rw-r--r--tdeioslaves/mbox/CMakeLists.txt36
-rw-r--r--tdeioslaves/mbox/Makefile.am30
-rw-r--r--tdeioslaves/mbox/README7
-rw-r--r--tdeioslaves/mbox/mbox.cc168
-rw-r--r--tdeioslaves/mbox/mbox.h81
-rw-r--r--tdeioslaves/mbox/mbox.protocol14
-rw-r--r--tdeioslaves/mbox/mboxfile.cc45
-rw-r--r--tdeioslaves/mbox/mboxfile.h68
-rw-r--r--tdeioslaves/mbox/readmbox.cc204
-rw-r--r--tdeioslaves/mbox/readmbox.h132
-rw-r--r--tdeioslaves/mbox/stat.cc115
-rw-r--r--tdeioslaves/mbox/stat.h82
-rw-r--r--tdeioslaves/mbox/urlinfo.cc133
-rw-r--r--tdeioslaves/mbox/urlinfo.h82
15 files changed, 1198 insertions, 0 deletions
diff --git a/tdeioslaves/mbox/AUTHORS b/tdeioslaves/mbox/AUTHORS
new file mode 100644
index 00000000..333010f6
--- /dev/null
+++ b/tdeioslaves/mbox/AUTHORS
@@ -0,0 +1 @@
+Mart Kelder <mart.kde@hccnet.nl>
diff --git a/tdeioslaves/mbox/CMakeLists.txt b/tdeioslaves/mbox/CMakeLists.txt
new file mode 100644
index 00000000..95ecdf49
--- /dev/null
+++ b/tdeioslaves/mbox/CMakeLists.txt
@@ -0,0 +1,36 @@
+#################################################
+#
+# (C) 2010-2011 Serghei Amelian
+# serghei (DOT) amelian (AT) gmail.com
+#
+# Improvements and feedback are welcome
+#
+# This file is released under GPL >= 2
+#
+#################################################
+
+include_directories(
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_SOURCE_DIR}/libtdepim
+ ${TDE_INCLUDE_DIR}
+ ${TQT_INCLUDE_DIRS}
+)
+
+link_directories(
+ ${TQT_LIBRARY_DIRS}
+)
+
+
+##### other data ################################
+
+install( FILES mbox.protocol DESTINATION ${SERVICES_INSTALL_DIR} )
+
+
+##### kio_mbox (module) #########################
+
+tde_add_kpart( kio_mbox
+ SOURCES
+ mbox.cc mboxfile.cc readmbox.cc stat.cc urlinfo.cc
+ LINK tdeio-shared
+ DESTINATION ${PLUGIN_INSTALL_DIR}
+)
diff --git a/tdeioslaves/mbox/Makefile.am b/tdeioslaves/mbox/Makefile.am
new file mode 100644
index 00000000..0fc50524
--- /dev/null
+++ b/tdeioslaves/mbox/Makefile.am
@@ -0,0 +1,30 @@
+INCLUDES= $(all_includes)
+
+####### Files
+
+METASOURCES = AUTO
+
+kde_module_LTLIBRARIES = kio_mbox.la
+
+kio_mbox_la_SOURCES = \
+ mbox.cc \
+ mboxfile.cc \
+ readmbox.cc \
+ stat.cc \
+ urlinfo.cc
+kio_mbox_la_LIBADD = $(LIB_KIO) $(LIB_QT) $(LIB_TDECORE)
+kio_mbox_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) -module $(KDE_PLUGIN)
+
+noinst_HEADERS = \
+ mbox.h \
+ mboxfile.h \
+ readmbox.h \
+ stat.h \
+ urlinfo.h
+
+kdelnk_DATA = mbox.protocol
+kdelnkdir = $(kde_servicesdir)
+
+
+include $(top_srcdir)/admin/Doxyfile.am
+
diff --git a/tdeioslaves/mbox/README b/tdeioslaves/mbox/README
new file mode 100644
index 00000000..7adae537
--- /dev/null
+++ b/tdeioslaves/mbox/README
@@ -0,0 +1,7 @@
+This is a simple tdeioslave for accessing mbox-files with kio.
+
+At the moment, it doesn't support locking or writing, it is just reading and listing messages.
+
+Usage:
+ mbox:/path/to/mbox/file For listing the files in a mbox-file
+ mbox:/path/to/mbox/file/id For getting an id out of a mbox-file.
diff --git a/tdeioslaves/mbox/mbox.cc b/tdeioslaves/mbox/mbox.cc
new file mode 100644
index 00000000..477ef350
--- /dev/null
+++ b/tdeioslaves/mbox/mbox.cc
@@ -0,0 +1,168 @@
+/*
+ * This is a simple tdeioslave to handle mbox-files.
+ * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "mbox.h"
+
+#include "readmbox.h"
+#include "stat.h"
+#include "urlinfo.h"
+
+#include <tqstring.h>
+#include <tqcstring.h>
+
+#include <kdebug.h>
+#include <klocale.h>
+#include <kinstance.h>
+#include <kglobal.h>
+#include <kurl.h>
+#include <tdeio/global.h>
+
+#include <stdlib.h>
+
+#include "tdepimmacros.h"
+
+#include "mbox.h"
+
+extern "C" { KDE_EXPORT int kdemain(int argc, char* argv[]); }
+
+int kdemain( int argc, char * argv[] )
+{
+ KLocale::setMainCatalogue("tdelibs");
+ TDEInstance instance("kio_mbox");
+ (void) TDEGlobal::locale();
+
+ if (argc != 4) {
+ fprintf(stderr, "Usage: kio_mbox protocol "
+ "domain-socket1 domain-socket2\n");
+ exit(-1);
+ }
+
+ MBoxProtocol slave(argv[2], argv[3]);
+ slave.dispatchLoop();
+
+ return 0;
+}
+
+MBoxProtocol::MBoxProtocol( const TQCString& arg1, const TQCString& arg2 )
+ : TDEIO::SlaveBase( "mbox2", arg1, arg2 ),
+ m_errorState( true )
+{
+
+}
+
+MBoxProtocol::~MBoxProtocol()
+{
+}
+
+void MBoxProtocol::get( const KURL& url )
+{
+ m_errorState = false;
+
+ UrlInfo info( url, UrlInfo::message );
+ TQString line;
+ TQByteArray ba_line;
+
+ if( info.type() == UrlInfo::invalid && !m_errorState )
+ {
+ error( TDEIO::ERR_DOES_NOT_EXIST, info.url() );
+ return;
+ }
+
+ ReadMBox mbox( &info, this );
+
+ while( !mbox.atEnd() && !m_errorState)
+ {
+ line = mbox.currentLine();
+ line += '\n';
+ ba_line = TQCString( line.utf8() );
+ ba_line.truncate( ba_line.size() - 1 ); //Removing training '\0'
+ data( ba_line );
+ mbox.nextLine();
+ };
+
+ if( !m_errorState )
+ {
+ data( TQByteArray() );
+ finished();
+ }
+}
+
+void MBoxProtocol::listDir( const KURL& url )
+{
+ m_errorState = false;
+
+ TDEIO::UDSEntry entry;
+ UrlInfo info( url, UrlInfo::directory );
+ ReadMBox mbox( &info, this, hasMetaData( "onlynew" ), hasMetaData( "savetime" ) );
+
+ if( m_errorState )
+ return;
+
+ if( info.type() != UrlInfo::directory )
+ {
+ error( TDEIO::ERR_DOES_NOT_EXIST, info.url() );
+ return;
+ }
+
+ while( !mbox.atEnd() && !m_errorState )
+ {
+ entry = Stat::stat( mbox, info );
+ if( mbox.inListing() )
+ listEntry( entry, false );
+ }
+
+ listEntry( TDEIO::UDSEntry(), true );
+ finished();
+}
+
+void MBoxProtocol::stat( const KURL& url )
+{
+ UrlInfo info( url );
+ if( info.type() == UrlInfo::invalid )
+ {
+ error( TDEIO::ERR_DOES_NOT_EXIST, url.path() );
+ return;
+ } else
+ {
+ statEntry( Stat::stat( info ) );
+ }
+ finished();
+}
+
+void MBoxProtocol::mimetype( const KURL& url )
+{
+ m_errorState = false;
+
+ UrlInfo info( url );
+
+ if( m_errorState )
+ return;
+
+ if( info.type() == UrlInfo::invalid )
+ error( TDEIO::ERR_DOES_NOT_EXIST, i18n( "Invalid URL" ) );
+ else
+ mimeType( info.mimetype() );
+ finished();
+}
+
+void MBoxProtocol::emitError( int errno, const TQString& arg )
+{
+ m_errorState = true;
+ error( errno, arg );
+}
+
diff --git a/tdeioslaves/mbox/mbox.h b/tdeioslaves/mbox/mbox.h
new file mode 100644
index 00000000..d6ef29ae
--- /dev/null
+++ b/tdeioslaves/mbox/mbox.h
@@ -0,0 +1,81 @@
+/*
+ * This is a simple tdeioslave to handle mbox-files.
+ * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef MBOX_H
+#define MBOX_H
+
+#include <tdeio/slavebase.h>
+
+class TQCString;
+class KURL;
+
+/**
+ * This class is the main class and implements all function
+ * which can be called through the user.
+ */
+class MBoxProtocol : public TDEIO::SlaveBase
+{
+public:
+ /**
+ * Constructor, for the parameters, See TDEIO::SlaveBase
+ */
+ MBoxProtocol( const TQCString&, const TQCString& );
+ /**
+ * Empty destructor
+ */
+ virtual ~MBoxProtocol();
+
+ /**
+ * This functions is used when an user or a program wants to
+ * get a file from a mbox-file
+ * @param url The url which points to the virtual file to get
+ */
+ virtual void get( const KURL& url );
+
+ /**
+ * This functions gives a listing back.
+ * @param url The url to the mbox-file.
+ */
+ virtual void listDir( const KURL& url );
+
+ /**
+ * This functions gives general properties about a mbox-file,
+ * or mbox-email back.
+ */
+ virtual void stat( const KURL& url );
+
+ /**
+ * This functions determinate the mimetype of a given mbox-file or mbox-email.
+ * @param url The url to get the mimetype from
+ */
+ virtual void mimetype( const KURL& url );
+
+ /**
+ * Through this functions, other class which have an instance to this
+ * class (classes which are part of kio_mbox) can emit an error with
+ * this function
+ * @param errno The error number to be thrown
+ * @param arg The argument of the error message of the error number.
+ */
+ void emitError( int errno, const TQString& arg );
+private:
+ bool m_errorState;
+};
+
+#endif
+
diff --git a/tdeioslaves/mbox/mbox.protocol b/tdeioslaves/mbox/mbox.protocol
new file mode 100644
index 00000000..8b6b412a
--- /dev/null
+++ b/tdeioslaves/mbox/mbox.protocol
@@ -0,0 +1,14 @@
+[Protocol]
+exec=kio_mbox
+protocol=mbox
+input=none
+output=filesystem
+listing=Name,Type,Size
+reading=true
+writing=false
+makedir=false
+deleting=false
+Icon=folder_inbox
+maxInstances=2
+DocPath=
+Class=:local
diff --git a/tdeioslaves/mbox/mboxfile.cc b/tdeioslaves/mbox/mboxfile.cc
new file mode 100644
index 00000000..7297457e
--- /dev/null
+++ b/tdeioslaves/mbox/mboxfile.cc
@@ -0,0 +1,45 @@
+/*
+ * This is a simple tdeioslave to handle mbox-files.
+ * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "mboxfile.h"
+
+#include <assert.h>
+
+MBoxFile::MBoxFile( const UrlInfo* info, MBoxProtocol* parent )
+ : m_info( info ),
+ m_mbox( parent )
+{
+ assert( m_info );
+}
+
+MBoxFile::~MBoxFile()
+{
+}
+
+bool MBoxFile::lock()
+{
+ //Not implemented
+ return true;
+}
+
+void MBoxFile::unlock()
+{
+ //Not implemented
+}
+
+
diff --git a/tdeioslaves/mbox/mboxfile.h b/tdeioslaves/mbox/mboxfile.h
new file mode 100644
index 00000000..1defafc9
--- /dev/null
+++ b/tdeioslaves/mbox/mboxfile.h
@@ -0,0 +1,68 @@
+/*
+ * This is a simple tdeioslave to handle mbox-files.
+ * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef MBOXFILE_H
+#define MBOXFILE_H
+class MBoxProtocol;
+class UrlInfo;
+
+/**
+ * This class can be used to lock files when implemented.
+ * It is a base class for all classes that needs locking and/ir
+ * an UrlInfo*.
+ */
+class MBoxFile
+{
+public:
+ /**
+ * Constructor
+ * @param info The urlinfo which must be used
+ * @param parent The MBoxProtocol parent instance, used to throw errors.
+ */
+ MBoxFile( const UrlInfo* info, MBoxProtocol* parent );
+
+ /**
+ * Empty destructor
+ */
+ ~MBoxFile();
+
+protected:
+ /**
+ * When implemented, this function handles the locking of the file.
+ * @return true if the locking was done succesfully.
+ */
+ bool lock();
+
+ /**
+ * When implemented, this function unlocks the file.
+ */
+ void unlock();
+
+protected:
+ /**
+ * This can be used to get information about the file.
+ * The file specified here is the file that must be used.
+ */
+ const UrlInfo* const m_info;
+
+ /**
+ * A instance of the parent protocol, meant to throw errors if neccesairy.
+ */
+ MBoxProtocol* const m_mbox;
+};
+#endif
diff --git a/tdeioslaves/mbox/readmbox.cc b/tdeioslaves/mbox/readmbox.cc
new file mode 100644
index 00000000..942f369e
--- /dev/null
+++ b/tdeioslaves/mbox/readmbox.cc
@@ -0,0 +1,204 @@
+/*
+ * This is a simple tdeioslave to handle mbox-files.
+ * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include <config.h>
+
+#include "readmbox.h"
+
+#include "mbox.h"
+#include "urlinfo.h"
+
+#include <kdebug.h>
+#include <tdeio/global.h>
+
+#include <tqfile.h>
+#include <tqfileinfo.h>
+#include <tqstring.h>
+#include <tqtextstream.h>
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#include <utime.h>
+
+ReadMBox::ReadMBox( const UrlInfo* info, MBoxProtocol* parent, bool onlynew, bool savetime )
+ : MBoxFile( info, parent ),
+ m_file( 0 ),
+ m_stream( 0 ),
+ m_current_line( new TQString( TQString() ) ),
+ m_current_id( new TQString( TQString() ) ),
+ m_atend( true ),
+ m_prev_time( 0 ),
+ m_only_new( onlynew ),
+ m_savetime( savetime ),
+ m_status( false ),
+ m_prev_status( false ),
+ m_header( true )
+
+{
+ if( m_info->type() == UrlInfo::invalid )
+ m_mbox->emitError( TDEIO::ERR_DOES_NOT_EXIST, info->url() );
+
+ if( !open( savetime ) )
+ m_mbox->emitError( TDEIO::ERR_CANNOT_OPEN_FOR_READING, info->url() );
+
+ if( m_info->type() == UrlInfo::message )
+ if( !searchMessage( m_info->id() ) )
+ m_mbox->emitError( TDEIO::ERR_DOES_NOT_EXIST, info->url() );
+}
+
+ReadMBox::~ReadMBox()
+{
+ delete m_current_line;
+ close();
+}
+
+TQString ReadMBox::currentLine() const
+{
+ return *m_current_line;
+}
+
+TQString ReadMBox::currentID() const
+{
+ return *m_current_id;
+}
+
+bool ReadMBox::nextLine()
+{
+ if( !m_stream )
+ return true;
+
+ *m_current_line = m_stream->readLine();
+ m_atend = m_current_line->isNull();
+ if( m_atend ) // Cursor was at EOF
+ {
+ *m_current_id = TQString();
+ m_prev_status = m_status;
+ return true;
+ }
+
+ //New message
+ if( m_current_line->left( 5 ) == "From " )
+ {
+ *m_current_id = *m_current_line;
+ m_prev_status = m_status;
+ m_status = true;
+ m_header = true;
+ return true;
+ } else if( m_only_new )
+ {
+ if( m_header && m_current_line->left( 7 ) == "Status:" &&
+ ! m_current_line->contains( "U" ) && ! m_current_line->contains( "N" ) )
+ {
+ m_status = false;
+ }
+ }
+
+ if( m_current_line->stripWhiteSpace().isEmpty() )
+ m_header = false;
+
+ return false;
+}
+
+bool ReadMBox::searchMessage( const TQString& id )
+{
+ if( !m_stream )
+ return false;
+
+ while( !m_atend && *m_current_id != id )
+ nextLine();
+
+ return *m_current_id == id;
+}
+
+unsigned int ReadMBox::skipMessage()
+{
+ unsigned int result = m_current_line->length();
+
+ if( !m_stream )
+ return 0;
+
+ while( !nextLine() )
+ result += m_current_line->length();
+
+ return result;
+}
+
+void ReadMBox::rewind()
+{
+ if( !m_stream )
+ return; //Rewinding not possible
+
+ m_stream->device()->reset();
+ m_atend = m_stream->atEnd();
+}
+
+bool ReadMBox::atEnd() const
+{
+ if( !m_stream )
+ return true;
+
+ return m_atend || ( m_info->type() == UrlInfo::message && *m_current_id != m_info->id() );
+}
+
+bool ReadMBox::inListing() const
+{
+ return !m_only_new || m_prev_status;
+}
+
+bool ReadMBox::open( bool savetime )
+{
+ if( savetime )
+ {
+ TQFileInfo info( m_info->filename() );
+
+ m_prev_time = new utimbuf;
+ m_prev_time->actime = info.lastRead().toTime_t();
+ m_prev_time->modtime = info.lastModified().toTime_t();
+ }
+
+ if( m_file )
+ return false; //File already open
+
+ m_file = new TQFile( m_info->filename() );
+ if( !m_file->open( IO_ReadOnly ) )
+ {
+ delete m_file;
+ m_file = 0;
+ return false;
+ }
+ m_stream = new TQTextStream( m_file );
+ skipMessage();
+
+ return true;
+}
+
+void ReadMBox::close()
+{
+ if( !m_stream )
+ return;
+
+ delete m_stream; m_stream = 0;
+ m_file->close();
+ delete m_file; m_file = 0;
+
+ if( m_prev_time )
+ utime( TQFile::encodeName( m_info->filename() ), m_prev_time );
+}
+
diff --git a/tdeioslaves/mbox/readmbox.h b/tdeioslaves/mbox/readmbox.h
new file mode 100644
index 00000000..0b887276
--- /dev/null
+++ b/tdeioslaves/mbox/readmbox.h
@@ -0,0 +1,132 @@
+/*
+ * This is a simple tdeioslave to handle mbox-files.
+ * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef READMBOX_H
+#define READMBOX_H
+
+#include "mboxfile.h"
+
+class UrlInfo;
+class MBox;
+
+class TQFile;
+class TQString;
+class TQTextStream;
+
+struct utimbuf;
+
+/**
+ * This class handels reading from a mbox-file.
+ */
+class ReadMBox : public MBoxFile
+{
+public:
+ /**
+ * Constructor
+ *
+ * @param info The information of the file to read
+ * @param parent The instance of the parent MBoxProtocol.
+ * @param onlynew Only read new messages from the MBox file.
+ * @param savetime If true, the atime of the mbox-file is preserved (note that this touch the ctime).
+ */
+ ReadMBox( const UrlInfo* info, MBoxProtocol* parent, bool onlynew = false, bool savetime = false );
+
+ /**
+ * Destructor
+ */
+ ~ReadMBox();
+
+ /**
+ * This functions return the current line
+ * @return The line last read, or TQString() if there wasn't such last line
+ */
+ TQString currentLine() const;
+
+ /**
+ * This function returns the current id. The id is the first line of an email,
+ * and is used in filenaming. The id normally starts with "From ".
+ * @return The current ID, or TQString() if no id was found yet.
+ */
+ TQString currentID() const;
+
+ /**
+ * This function reads the next line. The next line can be read by the currentLine()
+ * function call.
+ *
+ * @return true if succesfull, otherwise false.
+ */
+ bool nextLine();
+
+ /**
+ * This function search the file for a certain id.
+ * If not found, the position is EOF.
+ * @param id The id of the message to be found.
+ * @return true if the message was found, false otherwise.
+ */
+ bool searchMessage( const TQString& id );
+
+ /**
+ * Skips all lines which belongs to the current message. The cursor is on the first line
+ * of a new message message at the end of this function, or at EOF if the cursor was already
+ * on the last message.
+ * @return The number of bytes read while skipping the message.
+ */
+ unsigned int skipMessage();
+
+ /**
+ * Sets the cursor back to the beginning of the file
+ */
+ void rewind();
+
+ /**
+ * Returns true if the cursor is at EOF.
+ * @return true if and only if the cursor is at EOF.
+ */
+ bool atEnd() const;
+
+ /**
+ * Return true if the message is a new message, or all messages are listed
+ * @return true if it must be listed
+ */
+ bool inListing() const;
+private:
+ /**
+ * Opens a file
+ * @return true Returns true if opening was succesful.
+ */
+ bool open( bool savetime );
+
+ /**
+ * Closes a file.
+ */
+ void close();
+
+private:
+ TQFile* m_file;
+ TQTextStream* m_stream;
+ TQString* m_current_line;
+ TQString* m_current_id;
+ bool m_atend;
+
+ struct utimbuf* m_prev_time;
+
+ bool m_only_new, m_savetime;
+
+ bool m_status, m_prev_status, m_header;
+};
+#endif
diff --git a/tdeioslaves/mbox/stat.cc b/tdeioslaves/mbox/stat.cc
new file mode 100644
index 00000000..99267ca7
--- /dev/null
+++ b/tdeioslaves/mbox/stat.cc
@@ -0,0 +1,115 @@
+/*
+ * This is a simple tdeioslave to handle mbox-files.
+ * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "stat.h"
+
+#include "readmbox.h"
+#include "urlinfo.h"
+
+#include <kdebug.h>
+#include <tdeio/global.h>
+
+#include <sys/stat.h>
+
+TDEIO::UDSEntry Stat::stat( const UrlInfo& info )
+{
+ if( info.type() == UrlInfo::message )
+ return Stat::statMessage( info );
+ else if( info.type() == UrlInfo::directory )
+ return Stat::statDirectory( info );
+ else
+ return TDEIO::UDSEntry();
+}
+
+TDEIO::UDSEntry Stat::stat( ReadMBox& mbox, const UrlInfo& info )
+{
+ kdDebug() << "Stat::stat()" << endl;
+ TDEIO::UDSEntry entry;
+ TQString url;
+
+ if( info.type() == UrlInfo::invalid )
+ return entry;
+ else if( info.type() == UrlInfo::message )
+ mbox.searchMessage( info.id() );
+
+ Stat::addAtom( entry, TDEIO::UDS_FILE_TYPE, S_IFREG );
+ Stat::addAtom( entry, TDEIO::UDS_MIME_TYPE, "message/rfc822" );
+
+ url = TQString( "mbox:%1/%2" ).arg( info.filename(), mbox.currentID() );
+ Stat::addAtom( entry, TDEIO::UDS_URL, url );
+ if( mbox.currentID().isEmpty() )
+ Stat::addAtom( entry, TDEIO::UDS_NAME, "foobar" );
+ else
+ Stat::addAtom( entry, TDEIO::UDS_NAME, mbox.currentID() );
+
+
+ Stat::addAtom( entry, TDEIO::UDS_SIZE, mbox.skipMessage() );
+
+ return entry;
+}
+
+TDEIO::UDSEntry Stat::statDirectory( const UrlInfo& info )
+{
+ kdDebug() << "statDirectory()" << endl;
+ TDEIO::UDSEntry entry;
+
+ //Specific things for a directory
+ Stat::addAtom( entry, TDEIO::UDS_FILE_TYPE, S_IFDIR );
+ Stat::addAtom( entry, TDEIO::UDS_NAME, info.filename() );
+
+ return entry;
+}
+
+TDEIO::UDSEntry Stat::statMessage( const UrlInfo& info )
+{
+ kdDebug() << "statMessage( " << info.url() << " )" << endl;
+ TDEIO::UDSEntry entry;
+ TQString url = TQString( "mbox:%1" ).arg( info.url() );
+
+ //Specific things for a message
+ Stat::addAtom( entry, TDEIO::UDS_FILE_TYPE, S_IFREG );
+ Stat::addAtom( entry, TDEIO::UDS_MIME_TYPE, "message/rfc822" );
+
+ Stat::addAtom( entry, TDEIO::UDS_URL, url );
+ url = url.right( url.length() - url.findRev( "/" ) - 1 );
+ Stat::addAtom( entry, TDEIO::UDS_NAME, url );
+
+ return entry;
+}
+
+void Stat::addAtom( TDEIO::UDSEntry& entry, unsigned int uds, const TQString& str )
+{
+ TDEIO::UDSAtom atom;
+ atom.m_uds = uds;
+ atom.m_str = str;
+ atom.m_long = 0;
+
+ entry.append( atom );
+}
+
+
+void Stat::addAtom( TDEIO::UDSEntry& entry, unsigned int uds, long lng )
+{
+ TDEIO::UDSAtom atom;
+ atom.m_uds = uds;
+ atom.m_str = TQString();
+ atom.m_long = lng;
+
+ entry.append( atom );
+}
+
diff --git a/tdeioslaves/mbox/stat.h b/tdeioslaves/mbox/stat.h
new file mode 100644
index 00000000..4e2c1f02
--- /dev/null
+++ b/tdeioslaves/mbox/stat.h
@@ -0,0 +1,82 @@
+/*
+ * This is a simple tdeioslave to handle mbox-files.
+ * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef STAT_H
+#define STAT_H
+
+#include <tdeio/global.h>
+
+class ReadMBox;
+class UrlInfo;
+
+class KURL;
+
+class TQString;
+
+/**
+ * This class is used to get the stats of a mbox-email or mbox-file.
+ * This class only uses static members.
+ */
+class Stat
+{
+public:
+ /**
+ * Empty constructor
+ */
+ Stat() {}
+
+ /**
+ * Emtpy destructor
+ */
+ ~Stat() {}
+
+ /**
+ * This functions gives information with a given UrlInfo.
+ * @param info The file information
+ * @return The information of the file as destribed in UrlInfo.
+ */
+ static TDEIO::UDSEntry stat( const UrlInfo& info );
+ /**
+ * This function gives information with a given ReadMBox and UrlInfo.
+ * Through this, it is possible to ask the stats of the next message,
+ * without reopening the mbox-file.
+ * @param mbox The ReadMBox instance, used to search the mbox-email in.
+ * @param info The url information.
+ * @return The requesteds information.
+ */
+ static TDEIO::UDSEntry stat( ReadMBox& mbox, const UrlInfo& info );
+
+ /**
+ * This function gets the stats of a given mbox-file in an UDSEntry.
+ * @param info The location of the mbox-file.
+ * @return A list of Atoms.
+ */
+ static TDEIO::UDSEntry statDirectory( const UrlInfo& info );
+
+ /**
+ * This function gets the stats of a geven mbox-message in a UDSEntry.
+ * @param info The url of the mbox-message.
+ * @return Information shipped in an UDSEntry.
+ */
+ static TDEIO::UDSEntry statMessage( const UrlInfo& info );
+private:
+ static void addAtom( TDEIO::UDSEntry& entry, unsigned int key, const TQString& value );
+ static void addAtom( TDEIO::UDSEntry& entry, unsigned int key, const long value );
+};
+
+#endif
diff --git a/tdeioslaves/mbox/urlinfo.cc b/tdeioslaves/mbox/urlinfo.cc
new file mode 100644
index 00000000..4b359e40
--- /dev/null
+++ b/tdeioslaves/mbox/urlinfo.cc
@@ -0,0 +1,133 @@
+/*
+ * This is a simple tdeioslave to handle mbox-files.
+ * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "urlinfo.h"
+
+#include <kdebug.h>
+#include <kurl.h>
+
+#include <tqfileinfo.h>
+#include <tqstring.h>
+
+UrlInfo::UrlInfo( const KURL& url, const UrlType type )
+ : m_type( invalid ),
+ m_filename( new TQString ),
+ m_id( new TQString )
+{
+ calculateInfo( url, type );
+}
+
+UrlInfo::~UrlInfo()
+{
+ delete m_filename;
+ delete m_id;
+}
+
+TQString UrlInfo::mimetype() const
+{
+ switch( m_type )
+ {
+ case message:
+ return "message/rfc822";
+ case directory:
+ return "inode/directory";
+ case invalid:
+ default:
+ return "invalid";
+ }
+}
+
+TQString UrlInfo::filename() const
+{
+ return *m_filename;
+}
+
+TQString UrlInfo::id() const
+{
+ return *m_id;
+}
+
+TQString UrlInfo::url() const
+{
+ return *m_filename + "/" + *m_id;
+}
+
+
+void UrlInfo::calculateInfo( const KURL& url, const UrlType type )
+{
+ bool found = false;
+
+ if( !found && type & UrlInfo::message )
+ found = isMessage( url );
+ if( !found && type & UrlInfo::directory )
+ found = isDirectory( url );
+ if( !found )
+ {
+ m_type = invalid;
+ *m_filename = "";
+ *m_id = "";
+ }
+}
+
+bool UrlInfo::isDirectory( const KURL& url )
+{
+ //Check is url is in the form mbox://{filename}
+ TQString filename = url.path();
+ TQFileInfo info;
+
+ //Remove ending /
+ while( filename.length() > 1 && filename.right( 1 ) == "/" )
+ filename.remove( filename.length()-2, 1 );
+
+ //Is this a directory?
+ info.setFile( filename );
+ if( !info.isFile() )
+ return false;
+
+ //Setting paramaters
+ *m_filename = filename;
+ *m_id = TQString();
+ m_type = directory;
+ kdDebug() << "urlInfo::isDirectory( " << url << " )" << endl;
+ return true;
+}
+
+bool UrlInfo::isMessage( const KURL& url )
+{
+ TQString path = url.path();
+ TQFileInfo info;
+ int cutindex = path.findRev( '/' );
+
+ //Does it contain at least one /?
+ if( cutindex < 0 )
+ return false;
+
+ //Does the mbox-file exists?
+ info.setFile( path.left( cutindex ) );
+ if( !info.isFile() )
+ return false;
+
+ //Settings parameters
+ kdDebug() << "urlInfo::isMessage( " << url << " )" << endl;
+ m_type = message;
+ *m_id = path.right( path.length() - cutindex - 1 );
+ *m_filename = path.left( cutindex );
+
+ return true;
+}
+
diff --git a/tdeioslaves/mbox/urlinfo.h b/tdeioslaves/mbox/urlinfo.h
new file mode 100644
index 00000000..5de7804f
--- /dev/null
+++ b/tdeioslaves/mbox/urlinfo.h
@@ -0,0 +1,82 @@
+/*
+ * This is a simple tdeioslave to handle mbox-files.
+ * Copyright (C) 2004 Mart Kelder (mart.kde@hccnet.nl)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef URLINFO_H
+#define URLINFO_H
+class KURL;
+
+class TQString;
+
+class UrlInfo
+{
+public:
+ /**
+ * This enum is used to determe the url type.
+ */
+ enum UrlType { invalid = 0, message = 1, directory = 2 };
+
+ /**
+ * Constructor
+ *
+ * @param url The url: this url is used to split the location data off.
+ * @param type The possible types of the url
+ */
+ UrlInfo( const KURL &url, const UrlType type = (UrlType)( message | directory ) );
+
+ /**
+ * Destructor
+ */
+ ~UrlInfo();
+
+ /**
+ * Returns the type of the url
+ * @return the type of the url
+ */
+ UrlType type() const { return m_type; }
+
+ /**
+ * @return the mimetype of the url
+ */
+ TQString mimetype() const;
+
+ /**
+ * @return The location of the mbox-file
+ */
+ TQString filename() const;
+ /**
+ * @return The id given in the url.
+ */
+ TQString id() const;
+
+ /**
+ * @return the while url as TQString
+ */
+ TQString url() const;
+private:
+ void calculateInfo( const KURL& url, const UrlType type );
+
+ bool isDirectory( const KURL& url );
+ bool isMessage( const KURL& url );
+
+private:
+ UrlType m_type;
+ TQString *m_filename;
+ TQString *m_id;
+};
+
+#endif