File indexing completed on 2024-04-28 05:18:35
0001 /* 0002 SPDX-FileCopyrightText: 2009 Bertjan Broeksema <broeksema@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "mbox.h" 0010 0011 #include <QFile> 0012 #include <QObject> 0013 #include <QRegularExpression> 0014 #include <QTimer> 0015 0016 namespace KMBox 0017 { 0018 class MBoxPrivate : public QObject 0019 { 0020 Q_OBJECT 0021 0022 public: 0023 MBoxPrivate(MBox *mbox); 0024 0025 ~MBoxPrivate() override; 0026 0027 void close(); 0028 0029 void initLoad(const QString &fileName); 0030 0031 [[nodiscard]] bool open(); 0032 0033 [[nodiscard]] bool startTimerIfNeeded(); 0034 0035 [[nodiscard]] bool isMBoxSeparator(const QByteArray &line) const; 0036 0037 public Q_SLOTS: 0038 void unlockMBox(); 0039 0040 public: 0041 QByteArray mAppendedEntries; 0042 MBoxEntry::List mEntries; 0043 quint64 mInitialMboxFileSize = 0; 0044 QString mLockFileName; 0045 MBox *const mMBox; 0046 QFile mMboxFile; 0047 QTimer mUnlockTimer; 0048 static const QRegularExpression mSeparatorMatcher; 0049 MBox::LockType mLockType; 0050 bool mFileLocked = false; 0051 bool mReadOnly = false; 0052 0053 public: /// Static helper methods 0054 static QByteArray escapeFrom(const QByteArray &msg); 0055 0056 /** 0057 * Generates a mbox message separator line for given message. 0058 */ 0059 static QByteArray mboxMessageSeparator(const QByteArray &msg); 0060 0061 /** 0062 * Unescapes the raw message read from the file. 0063 */ 0064 static void unescapeFrom(char *msg, size_t size); 0065 }; 0066 }