You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
134 lines
2.9 KiB
134 lines
2.9 KiB
15 years ago
|
/*
|
||
12 years ago
|
* This is a simple tdeioslave to handle mbox-files.
|
||
15 years ago
|
* 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>
|
||
|
|
||
15 years ago
|
#include <tqfileinfo.h>
|
||
|
#include <tqstring.h>
|
||
15 years ago
|
|
||
|
UrlInfo::UrlInfo( const KURL& url, const UrlType type )
|
||
|
: m_type( invalid ),
|
||
15 years ago
|
m_filename( new TQString ),
|
||
|
m_id( new TQString )
|
||
15 years ago
|
{
|
||
|
calculateInfo( url, type );
|
||
|
}
|
||
|
|
||
|
UrlInfo::~UrlInfo()
|
||
|
{
|
||
|
delete m_filename;
|
||
|
delete m_id;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString UrlInfo::mimetype() const
|
||
15 years ago
|
{
|
||
|
switch( m_type )
|
||
|
{
|
||
|
case message:
|
||
|
return "message/rfc822";
|
||
|
case directory:
|
||
|
return "inode/directory";
|
||
|
case invalid:
|
||
|
default:
|
||
|
return "invalid";
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString UrlInfo::filename() const
|
||
15 years ago
|
{
|
||
|
return *m_filename;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString UrlInfo::id() const
|
||
15 years ago
|
{
|
||
|
return *m_id;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString UrlInfo::url() const
|
||
15 years ago
|
{
|
||
|
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}
|
||
15 years ago
|
TQString filename = url.path();
|
||
|
TQFileInfo info;
|
||
15 years ago
|
|
||
|
//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;
|
||
14 years ago
|
*m_id = TQString();
|
||
15 years ago
|
m_type = directory;
|
||
|
kdDebug() << "urlInfo::isDirectory( " << url << " )" << endl;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool UrlInfo::isMessage( const KURL& url )
|
||
|
{
|
||
15 years ago
|
TQString path = url.path();
|
||
|
TQFileInfo info;
|
||
13 years ago
|
int cutindex = path.findRev( '/' );
|
||
15 years ago
|
|
||
|
//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;
|
||
|
}
|
||
|
|