/*
  filter_oe.h  -  Outlook Express mail import

  SPDX-FileCopyrightText: 2003 Laurence Anderson <l.d.anderson@warwick.ac.uk>

  SPDX-License-Identifier: GPL-2.0-or-later
*/

#pragma once

#include "filters.h"

#include <QList>

#include "mailimporter_utils.h"
namespace MailImporter
{
/*!
 * \class MailImporter::FilterOE
 * \inmodule MailImporter
 * \inheaderfile MailImporter/FilterOE
 *
 * \brief imports outlook text messages into KMail.
 * \author Laurence Anderson
 */
class MAILIMPORTER_EXPORT FilterOE : public Filter
{
public:
    /*!
     * \brief Constructor for FilterOE.
     */
    FilterOE();
    /*!
     * \brief Destructor for FilterOE.
     */
    ~FilterOE() override;

    /*!
     * \brief Imports Outlook Express mail files.
     */
    void import() override;
    /*!
     * \brief Imports mails from the specified directory.
     * \param maildir The mail directory to import from
     */
    void importMails(const QString &maildir);

private:
    MAILIMPORTER_NO_EXPORT void importMailBox(const QString &fileName);
    MAILIMPORTER_NO_EXPORT void mbxImport(QDataStream &ds);
    MAILIMPORTER_NO_EXPORT void dbxImport(QDataStream &ds);
    MAILIMPORTER_NO_EXPORT void dbxReadIndex(QDataStream &ds, int filePos);
    MAILIMPORTER_NO_EXPORT void dbxReadDataBlock(QDataStream &ds, int filePos);
    MAILIMPORTER_NO_EXPORT void dbxReadEmail(QDataStream &ds, int filePos);

    /*! helperfunctions for folder structure support */
    [[nodiscard]] MAILIMPORTER_NO_EXPORT QString parseFolderOEString(QDataStream &ds, int filePos);
    [[nodiscard]] MAILIMPORTER_NO_EXPORT QString getFolderName(const QString &filename);

    /*! which file (of totalFiles) is now in the work? */
    int currentFile;
    /*! total number of files that get imported */
    int totalFiles;
    /*! total emails in current file */
    int totalEmails;
    /*! which email (of totalFiles) is now in the work? */
    int currentEmail;
    /*! number of imported mails with flag 0x04 */
    int count0x04;
    /*! number of imported mails with flag 0x84 */
    int count0x84;

    /*! true if the folderstructure is parsed */
    bool parsedFolder;
    /*! true if the current parsing file is the folder file */
    bool currentIsFolderFile;

    /*! Folder structure with following  4 entries:
      1. descriptive folder name
      2. filename
      3. ID of current folder
      4. ID of parent folder
    */
    using FolderStructure = FolderStructureBase<4>;
    /*! matrix with information about the folder structure*/
    QList<FolderStructure> folderStructure;
    using FolderStructureIterator = QList<FolderStructure>::Iterator;

    /*! name of the current folder */
    QString folderName;
    /*! name of the chosen folder */
};
}
