diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-15 17:05:20 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-15 17:05:20 +0100 |
commit | 1710fab0965d32b883dfcc327c36d3fd38a91357 (patch) | |
tree | 1ba0d5d4728ff6405846a99549293a4b4c69da25 /examples/maildirresource/libmaildir/maildir.h | |
parent | 62d74778fa315091c5f0b99093bd806a1ccd7a79 (diff) | |
download | sink-1710fab0965d32b883dfcc327c36d3fd38a91357.tar.gz sink-1710fab0965d32b883dfcc327c36d3fd38a91357.zip |
A read-only maildir resource.
Respectively a first prototype thereof.
Diffstat (limited to 'examples/maildirresource/libmaildir/maildir.h')
-rw-r--r-- | examples/maildirresource/libmaildir/maildir.h | 266 |
1 files changed, 266 insertions, 0 deletions
diff --git a/examples/maildirresource/libmaildir/maildir.h b/examples/maildirresource/libmaildir/maildir.h new file mode 100644 index 0000000..6853033 --- /dev/null +++ b/examples/maildirresource/libmaildir/maildir.h | |||
@@ -0,0 +1,266 @@ | |||
1 | /* | ||
2 | Copyright (c) 2007 Till Adam <adam@kde.org> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | |||
20 | #ifndef MAILDIR_H | ||
21 | #define MAILDIR_H | ||
22 | |||
23 | |||
24 | #include "maildir_export.h" | ||
25 | |||
26 | #include <QString> | ||
27 | #include <QStringList> | ||
28 | |||
29 | class QDateTime; | ||
30 | |||
31 | namespace KPIM { | ||
32 | |||
33 | class MAILDIR_EXPORT Maildir | ||
34 | { | ||
35 | public: | ||
36 | /** | ||
37 | Create a new Maildir object. | ||
38 | @param path The path to the maildir, if @p isRoot is @c false, that's the path | ||
39 | to the folder containing the cur/new/tmp folders, if @p isRoot is @c true this | ||
40 | is the path to a folder containing a number of maildirs. | ||
41 | @param isRoot Indicate whether this is a maildir containing mails and various | ||
42 | sub-folders or a container only containing maildirs. | ||
43 | */ | ||
44 | explicit Maildir( const QString& path = QString(), bool isRoot = false ); | ||
45 | /* Copy constructor */ | ||
46 | Maildir(const Maildir & rhs); | ||
47 | /* Copy operator */ | ||
48 | Maildir& operator=(const Maildir & rhs); | ||
49 | /** Equality comparison */ | ||
50 | bool operator==(const Maildir & rhs) const; | ||
51 | /* Destructor */ | ||
52 | ~Maildir(); | ||
53 | |||
54 | /** Returns whether the maildir has all the necessary subdirectories, | ||
55 | * that they are readable, etc. | ||
56 | * @param createMissingFolders if true (the default), the cur/new/tmp folders are created if they are missing | ||
57 | */ | ||
58 | bool isValid( bool createMissingFolders = true ) const; | ||
59 | |||
60 | /** | ||
61 | * Returns whether this is a normal maildir or a container containing maildirs. | ||
62 | */ | ||
63 | bool isRoot() const; | ||
64 | |||
65 | /** | ||
66 | * Make a valid maildir at the path of this Maildir object. This involves | ||
67 | * creating the necessary subdirs, etc. Note that an empty Maildir is | ||
68 | * not valid, unless it is given valid path, or until create( ) is | ||
69 | * called on it. | ||
70 | */ | ||
71 | bool create(); | ||
72 | |||
73 | /** | ||
74 | * Returns the path of this maildir. | ||
75 | */ | ||
76 | QString path() const; | ||
77 | |||
78 | /** | ||
79 | * Returns the name of this maildir. | ||
80 | */ | ||
81 | QString name() const; | ||
82 | |||
83 | /** | ||
84 | * Returns the list of items (mails) in the maildir. These are keys, which | ||
85 | * map to filenames, internally, but that's an implementation detail, which | ||
86 | * should not be relied on. | ||
87 | */ | ||
88 | QStringList entryList() const; | ||
89 | |||
90 | /** Returns the list of items (mails) in the maildirs "new" folder. These are keys, which | ||
91 | * map to filenames, internally, but that's an implementation detail, which | ||
92 | * should not be relied on. | ||
93 | */ | ||
94 | QStringList listNew() const; | ||
95 | |||
96 | /** Returns the list of items (mails) in the maildirs "cur" folder. These are keys, which | ||
97 | * map to filenames, internally, but that's an implementation detail, which | ||
98 | * should not be relied on. | ||
99 | */ | ||
100 | QStringList listCurrent() const; | ||
101 | |||
102 | /** Return the path to the "new" directory */ | ||
103 | QString pathToNew() const; | ||
104 | |||
105 | /** Return the path to the "cur" directory */ | ||
106 | QString pathToCurrent() const; | ||
107 | |||
108 | /** | ||
109 | * Returns the full path to the subdir (the NAME.directory folder ). | ||
110 | **/ | ||
111 | QString subDirPath() const; | ||
112 | |||
113 | /** | ||
114 | * Return the full path to the file identified by key (it can be either in the "new" or "cur" folder | ||
115 | **/ | ||
116 | QString findRealKey( const QString& key ) const; | ||
117 | |||
118 | /** | ||
119 | * Returns the list of subfolders, as names (relative paths). Use the | ||
120 | * subFolder method to get Maildir objects representing them. | ||
121 | */ | ||
122 | QStringList subFolderList() const; | ||
123 | |||
124 | /** | ||
125 | * Adds subfolder with the given @p folderName. | ||
126 | * @return an empty string on failure or the full path of the new subfolder | ||
127 | * on success | ||
128 | */ | ||
129 | QString addSubFolder( const QString& folderName ); | ||
130 | |||
131 | /** | ||
132 | * Removes subfolder with the given @p folderName. Returns success or failure. | ||
133 | */ | ||
134 | bool removeSubFolder( const QString& folderName ); | ||
135 | |||
136 | /** | ||
137 | * Returns a Maildir object for the given @p folderName. If such a folder | ||
138 | * exists, the Maildir object will be valid, otherwise you can call create() | ||
139 | * on it, to make a subfolder with that name. | ||
140 | */ | ||
141 | Maildir subFolder( const QString& folderName ) const; | ||
142 | |||
143 | /** | ||
144 | * Returns the parent Maildir object for this Maildir, if there is one (ie. this is not the root). | ||
145 | */ | ||
146 | Maildir parent() const; | ||
147 | |||
148 | /** | ||
149 | * Returns the size of the file in the maildir with the given @p key or \c -1 if key is not valid. | ||
150 | * @since 4.2 | ||
151 | */ | ||
152 | qint64 size( const QString& key ) const; | ||
153 | |||
154 | /** | ||
155 | * Returns the modification time of the file in the maildir with the given @p key. | ||
156 | * @since 4.7 | ||
157 | */ | ||
158 | QDateTime lastModified( const QString &key ) const; | ||
159 | |||
160 | /** | ||
161 | * Return the contents of the file in the maildir with the given @p key. | ||
162 | */ | ||
163 | QByteArray readEntry( const QString& key ) const; | ||
164 | |||
165 | enum MailFlags { | ||
166 | Forwarded, | ||
167 | Replied, | ||
168 | Seen, | ||
169 | Flagged | ||
170 | }; | ||
171 | Q_DECLARE_FLAGS(Flags, MailFlags); | ||
172 | |||
173 | /** | ||
174 | * Return the flags encoded in the maildir file name for an entry | ||
175 | **/ | ||
176 | Flags readEntryFlags( const QString& key ) const; | ||
177 | |||
178 | /** | ||
179 | * Return the contents of the headers section of the file the maildir with the given @p file, that | ||
180 | * is a full path to the file. You can get it by using findRealKey(key) . | ||
181 | */ | ||
182 | QByteArray readEntryHeadersFromFile( const QString& file ) const; | ||
183 | |||
184 | /** | ||
185 | * Return the contents of the headers section of the file the maildir with the given @p key. | ||
186 | */ | ||
187 | QByteArray readEntryHeaders( const QString& key ) const; | ||
188 | |||
189 | /** | ||
190 | * Write the given @p data to a file in the maildir with the given @p key. | ||
191 | * Returns true in case of success, false in case of any error. | ||
192 | */ | ||
193 | bool writeEntry( const QString& key, const QByteArray& data ); | ||
194 | |||
195 | /** | ||
196 | * Adds the given @p data to the maildir. Returns the key of the entry. | ||
197 | */ | ||
198 | QString addEntry( const QByteArray& data ); | ||
199 | |||
200 | /** | ||
201 | * Removes the entry with the given @p key. Returns success or failure. | ||
202 | */ | ||
203 | bool removeEntry( const QString& key ); | ||
204 | |||
205 | /** | ||
206 | * Change the flags for an entry specified by @p key. Returns the new key of the entry (the key might change because | ||
207 | * flags are stored in the unique filename). | ||
208 | */ | ||
209 | // QString changeEntryFlags( const QString& key, const Akonadi::Item::Flags& flags ); | ||
210 | |||
211 | /** | ||
212 | * Moves this maildir into @p destination. | ||
213 | */ | ||
214 | bool moveTo( const Maildir &destination ); | ||
215 | |||
216 | /** | ||
217 | * Renames this maildir to @p newName. | ||
218 | */ | ||
219 | bool rename( const QString &newName ); | ||
220 | |||
221 | /** | ||
222 | * Moves the file with the given @p key into the Maildir @p destination. | ||
223 | * @returns The new file name inside @p destination. | ||
224 | */ | ||
225 | QString moveEntryTo( const QString& key, const KPIM::Maildir& destination ); | ||
226 | |||
227 | /** | ||
228 | * Creates the maildir tree structure specific directory path that the | ||
229 | * given @p folderPath folder would have for its sub folders | ||
230 | * @param folderPath a maildir folder path | ||
231 | * @return the relative subDirPath for the given @p folderPath | ||
232 | * | ||
233 | * @see subDirNameForFolderName() | ||
234 | */ | ||
235 | static QString subDirPathForFolderPath( const QString &folderPath ); | ||
236 | |||
237 | /** | ||
238 | * Creates the maildir tree structure specific directory name that the | ||
239 | * given @p folderName folder would have for its sub folders | ||
240 | * @param folderName a maildir folder name | ||
241 | * @return the relative subDirName for the given @p folderMame | ||
242 | * | ||
243 | * @see subDirPathForFolderPath() | ||
244 | */ | ||
245 | static QString subDirNameForFolderName( const QString &folderName ); | ||
246 | |||
247 | /** Removes the listed keys from the key cache */ | ||
248 | void removeCachedKeys(const QStringList & keys); | ||
249 | |||
250 | |||
251 | /** Reloads the keys associated with the maildir in the key cache*/ | ||
252 | void refreshKeyCache(); | ||
253 | |||
254 | /** Return the last error message string. The error might not come from the last performed operation, | ||
255 | if that was sucessful. The caller should always check the return value of the methods before | ||
256 | querying the last error string. */ | ||
257 | QString lastError() const; | ||
258 | |||
259 | private: | ||
260 | void swap( const Maildir& ); | ||
261 | class Private; | ||
262 | Private *d; | ||
263 | }; | ||
264 | |||
265 | } | ||
266 | #endif // __MAILDIR_H__ | ||