summaryrefslogtreecommitdiffstats
path: root/tdeioslaves/mbox/readmbox.h
blob: 0b88727636c80780c32ec2c2f924c7404fa7b484 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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