27 #include <tdeio/global.h>
30 #include <tqfileinfo.h>
32 #include <tqtextstream.h>
34 #ifdef HAVE_SYS_TYPES_H
35 #include <sys/types.h>
44 m_current_line( new TQString( TQString() ) ),
45 m_current_id( new TQString( TQString() ) ),
48 m_only_new( onlynew ),
49 m_savetime( savetime ),
51 m_prev_status( false ),
55 if(
m_info->type() == UrlInfo::invalid )
58 if( !open( savetime ) )
61 if(
m_info->type() == UrlInfo::message )
68 delete m_current_line;
74 return *m_current_line;
87 *m_current_line = m_stream->readLine();
88 m_atend = m_current_line->isNull();
91 *m_current_id = TQString();
92 m_prev_status = m_status;
97 if( m_current_line->left( 5 ) ==
"From " )
99 *m_current_id = *m_current_line;
100 m_prev_status = m_status;
104 }
else if( m_only_new )
106 if( m_header && m_current_line->left( 7 ) ==
"Status:" &&
107 ! m_current_line->contains(
"U" ) && ! m_current_line->contains(
"N" ) )
113 if( m_current_line->stripWhiteSpace().isEmpty() )
124 while( !m_atend && *m_current_id !=
id )
127 return *m_current_id == id;
132 unsigned int result = m_current_line->length();
138 result += m_current_line->length();
148 m_stream->device()->reset();
149 m_atend = m_stream->atEnd();
157 return m_atend || (
m_info->type() == UrlInfo::message && *m_current_id !=
m_info->id() );
162 return !m_only_new || m_prev_status;
165 bool ReadMBox::open(
bool savetime )
169 TQFileInfo info(
m_info->filename() );
171 m_prev_time =
new utimbuf;
172 m_prev_time->actime = info.lastRead().toTime_t();
173 m_prev_time->modtime = info.lastModified().toTime_t();
179 m_file =
new TQFile(
m_info->filename() );
180 if( !m_file->open( IO_ReadOnly ) )
186 m_stream =
new TQTextStream( m_file );
192 void ReadMBox::close()
197 delete m_stream; m_stream = 0;
199 delete m_file; m_file = 0;
202 utime( TQFile::encodeName(
m_info->filename() ), m_prev_time );
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 TQString &arg)
Through this functions, other class which have an instance to this class (classes which are part of t...
bool nextLine()
This function reads the next line.
ReadMBox(const UrlInfo *info, MBoxProtocol *parent, bool onlynew=false, bool savetime=false)
Constructor.
TQString currentID() const
This function returns the current id.
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.
TQString currentLine() const
This functions return the current line.
bool atEnd() const
Returns true if the cursor is at EOF.
unsigned int skipMessage()
Skips all lines which belongs to the current message.
bool searchMessage(const TQString &id)
This function search the file for a certain id.