24#include <kio/global.h>
40 m_only_new( onlynew ),
41 m_savetime( savetime ),
43 m_prev_status( false ),
46 if(
m_info->type() == UrlInfo::invalid ) {
47 m_mbox->emitError( KIO::ERR_DOES_NOT_EXIST, info->url() );
50 if( !open( savetime ) ) {
54 if(
m_info->type() == UrlInfo::message ) {
55 if( !searchMessage( m_info->id() ) ) {
56 m_mbox->emitError( KIO::ERR_DOES_NOT_EXIST, info->url() );
68 return m_current_line;
82 m_current_line = m_stream->readLine();
83 m_atend = m_current_line.isNull();
86 m_prev_status = m_status;
91 if( m_current_line.left( 5 ) ==
"From " ) {
92 m_current_id = m_current_line;
93 m_prev_status = m_status;
97 }
else if( m_only_new ) {
98 if( m_header && m_current_line.left( 7 ) ==
"Status:" &&
99 ! m_current_line.contains(
"U" ) && ! m_current_line.contains(
"N" ) ) {
104 if( m_current_line.trimmed().isEmpty() ) {
117 while( !m_atend && m_current_id !=
id ) {
121 return m_current_id == id;
126 unsigned int result = m_current_line.length();
133 result += m_current_line.length();
145 m_stream->device()->reset();
146 m_atend = m_stream->atEnd();
154 return m_atend || (
m_info->type() == UrlInfo::message && m_current_id !=
m_info->id() );
159 return !m_only_new || m_prev_status;
162bool ReadMBox::open(
bool savetime )
165 QFileInfo info(
m_info->filename() );
167 m_prev_time =
new utimbuf;
168 m_prev_time->actime = info.lastRead().toTime_t();
169 m_prev_time->modtime = info.lastModified().toTime_t();
176 m_file =
new QFile(
m_info->filename() );
177 if( !m_file->open( QIODevice::ReadOnly ) ) {
182 m_stream =
new QTextStream( m_file );
188void ReadMBox::close()
194 delete m_stream; m_stream = 0;
196 delete m_file; m_file = 0;
199 utime( QFile::encodeName(
m_info->filename() ), m_prev_time );
200 delete m_prev_time; m_prev_time = 0;
This class can be used to lock files when implemented.
const UrlInfo *const m_info
This can be used to get information about the file.
MBoxProtocol *const m_mbox
A instance of the parent protocol, meant to throw errors if neccesairy.
This class is the main class and implements all function which can be called through the user.
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...
bool nextLine()
This function reads the next line.
ReadMBox(const UrlInfo *info, MBoxProtocol *parent, bool onlynew=false, bool savetime=false)
Constructor.
QString currentLine() const
This functions return the current line.
void rewind()
Sets the cursor back to the beginning of the file.
bool inListing() const
Return true if the message is a new message, or all messages are listed.
bool searchMessage(const QString &id)
This function search the file for a certain id.
bool atEnd() const
Returns true if the cursor is at EOF.
unsigned int skipMessage()
Skips all lines which belongs to the current message.
QString currentID() const
This function returns the current id.