diff options
Diffstat (limited to 'kioslaves/mbox')
-rw-r--r-- | kioslaves/mbox/AUTHORS | 1 | ||||
-rw-r--r-- | kioslaves/mbox/CMakeLists.txt | 36 | ||||
-rw-r--r-- | kioslaves/mbox/Makefile.am | 30 | ||||
-rw-r--r-- | kioslaves/mbox/README | 7 | ||||
-rw-r--r-- | kioslaves/mbox/mbox.cc | 168 | ||||
-rw-r--r-- | kioslaves/mbox/mbox.h | 81 | ||||
-rw-r--r-- | kioslaves/mbox/mbox.protocol | 14 | ||||
-rw-r--r-- | kioslaves/mbox/mboxfile.cc | 45 | ||||
-rw-r--r-- | kioslaves/mbox/mboxfile.h | 68 | ||||
-rw-r--r-- | kioslaves/mbox/readmbox.cc | 204 | ||||
-rw-r--r-- | kioslaves/mbox/readmbox.h | 132 | ||||
-rw-r--r-- | kioslaves/mbox/stat.cc | 115 | ||||
-rw-r--r-- | kioslaves/mbox/stat.h | 82 | ||||
-rw-r--r-- | kioslaves/mbox/urlinfo.cc | 133 | ||||
-rw-r--r-- | kioslaves/mbox/urlinfo.h | 82 |
15 files changed, 0 insertions, 1198 deletions
diff --git a/kioslaves/mbox/AUTHORS b/kioslaves/mbox/AUTHORS deleted file mode 100644 index 333010f6c..000000000 --- a/kioslaves/mbox/AUTHORS +++ /dev/null @@ -1 +0,0 @@ -Mart Kelder <mart.kde@hccnet.nl> diff --git a/kioslaves/mbox/CMakeLists.txt b/kioslaves/mbox/CMakeLists.txt deleted file mode 100644 index b823d8b93..000000000 --- a/kioslaves/mbox/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -################################################# -# -# (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 kio-shared - DESTINATION ${PLUGIN_INSTALL_DIR} -) diff --git a/kioslaves/mbox/Makefile.am b/kioslaves/mbox/Makefile.am deleted file mode 100644 index 0fc505249..000000000 --- a/kioslaves/mbox/Makefile.am +++ /dev/null @@ -1,30 +0,0 @@ -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/kioslaves/mbox/README b/kioslaves/mbox/README deleted file mode 100644 index f0441661c..000000000 --- a/kioslaves/mbox/README +++ /dev/null @@ -1,7 +0,0 @@ -This is a simple kioslave 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/kioslaves/mbox/mbox.cc b/kioslaves/mbox/mbox.cc deleted file mode 100644 index 0c4fca815..000000000 --- a/kioslaves/mbox/mbox.cc +++ /dev/null @@ -1,168 +0,0 @@ -/* - * This is a simple kioslave 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 <kio/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/kioslaves/mbox/mbox.h b/kioslaves/mbox/mbox.h deleted file mode 100644 index 159c4213e..000000000 --- a/kioslaves/mbox/mbox.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * This is a simple kioslave 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 <kio/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/kioslaves/mbox/mbox.protocol b/kioslaves/mbox/mbox.protocol deleted file mode 100644 index 8b6b412a8..000000000 --- a/kioslaves/mbox/mbox.protocol +++ /dev/null @@ -1,14 +0,0 @@ -[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/kioslaves/mbox/mboxfile.cc b/kioslaves/mbox/mboxfile.cc deleted file mode 100644 index 271b71019..000000000 --- a/kioslaves/mbox/mboxfile.cc +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This is a simple kioslave 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/kioslaves/mbox/mboxfile.h b/kioslaves/mbox/mboxfile.h deleted file mode 100644 index b8a98973e..000000000 --- a/kioslaves/mbox/mboxfile.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * This is a simple kioslave 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/kioslaves/mbox/readmbox.cc b/kioslaves/mbox/readmbox.cc deleted file mode 100644 index 3125fd747..000000000 --- a/kioslaves/mbox/readmbox.cc +++ /dev/null @@ -1,204 +0,0 @@ -/* - * This is a simple kioslave 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 <kio/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/kioslaves/mbox/readmbox.h b/kioslaves/mbox/readmbox.h deleted file mode 100644 index 046767be7..000000000 --- a/kioslaves/mbox/readmbox.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * This is a simple kioslave 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/kioslaves/mbox/stat.cc b/kioslaves/mbox/stat.cc deleted file mode 100644 index c5d9a3bdf..000000000 --- a/kioslaves/mbox/stat.cc +++ /dev/null @@ -1,115 +0,0 @@ -/* - * This is a simple kioslave 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 <kio/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/kioslaves/mbox/stat.h b/kioslaves/mbox/stat.h deleted file mode 100644 index 8ce593cc0..000000000 --- a/kioslaves/mbox/stat.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * This is a simple kioslave 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 <kio/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/kioslaves/mbox/urlinfo.cc b/kioslaves/mbox/urlinfo.cc deleted file mode 100644 index d59c77ac8..000000000 --- a/kioslaves/mbox/urlinfo.cc +++ /dev/null @@ -1,133 +0,0 @@ -/* - * This is a simple kioslave 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/kioslaves/mbox/urlinfo.h b/kioslaves/mbox/urlinfo.h deleted file mode 100644 index 96882d1db..000000000 --- a/kioslaves/mbox/urlinfo.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * This is a simple kioslave 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 |