<commit_before>#if !defined(_IMAPSESSION_HPP_INCLUDED_)
#define _IMAPSESSION_HPP_INCLUDED_

#include <iostream>

#include <map>
#include <string>

#include <stdint.h>

#include <libcppserver/insensitive.hpp>
#include <libcppserver/internetsession.hpp>
#include <libcppserver/internetserver.hpp>
#include <libcppserver/sessiondriver.hpp>

#include "imapuser.hpp"
#include "namespace.hpp"
#include "sasl.hpp"
#include "mailsearch.hpp"
#include "mailmessage.hpp"

class ImapMaster;
class SessionDriver;
class MailSearch;
class MailMessage;

enum ImapState
  {
    ImapNotAuthenticated = 0,
    ImapAuthenticated,
    ImapSelected,
    ImapLogoff
  };

enum ImapStringState
  {
    ImapStringGood,
    ImapStringBad,
    ImapStringPending
  };

/*--------------------------------------------------------------------------------------*/
//* Imap											*/
/*--------------------------------------------------------------------------------------*/

class ImapSession;

typedef enum
  {
    IMAP_OK,
    IMAP_NO,
    IMAP_BAD,
    IMAP_NOTDONE,
    IMAP_NO_WITH_PAUSE,
    IMAP_MBOX_ERROR,
    IMAP_IN_LITERAL,
    IMAP_TRY_AGAIN
  } IMAP_RESULTS;

#define MAX_RESPONSE_STRING_LENGTH	80
#define IMAP_BUFFER_LEN			8192

typedef struct {
  bool levels[ImapLogoff+1];
  bool sendUpdatedStatus;
  // The flag is a bit of an odd duck.  It's here because I need to pass what essentially amounts to random bools to the
  // handler.  It means different things for different methods.
  // It distinguishes subscribe (flag = true) from unsubscribe (flag = false)
  // It distinguishes list (flag = true) from lsub (flag = false)
  // It distinguishes examine (flag = true) from select (flag = false)
  // It distinguishes uid (flag = true) from copy, close, search, fetch, and store (flag = false)
  bool flag;
  IMAP_RESULTS (ImapSession::*handler)(uint8_t *data, size_t dataLen, size_t &parsingAt, bool flag);
} symbol;

typedef std::map<insensitiveString, symbol> IMAPSYMBOLS;

class ImapSession : public InternetSession {
public:
  ImapSession(ImapMaster *master, SessionDriver *driver, InternetServer *server);
  virtual ~ImapSession();
  static void BuildSymbolTables(void);
  void ReceiveData(uint8_t* pData, size_t dwDataLen );

  void AsynchronousEvent(void);
  ImapMaster *GetMaster(void) const { return m_master; }
  InternetServer *GetServer(void) const { return m_server; }
  SessionDriver *GetDriver(void) const { return m_driver; };
  time_t GetLastCommandTime() const { return m_lastCommandTime; }
  ImapState GetState(void) const { return m_state; }
  const ImapUser *GetUser(void) const { return m_userData; }
  // ReceiveData processes data as it comes it.  It's primary job is to chop the incoming data into
  // lines and to pass each line to HandleOneLine, which is the core command processor for the system
  void HandleOneLine(uint8_t *pData, size_t dwDataLen);
  void DoRetry(void);
  void IdleTimeout(void);

private:
  // These are configuration items
  bool m_LoginDisabled;
  static bool m_anonymousEnabled;
  unsigned m_failedLoginPause;
  SessionDriver *m_driver;
  MailStore::MAIL_STORE_RESULT m_mboxErrorCode;

  // These constitute the session's state
  enum ImapState m_state;
  IMAP_RESULTS (ImapSession::*m_currentHandler)(uint8_t *data, const size_t dataLen, size_t &parsingAt, bool flag);<commit_msg>ReceiveData is really a virtual function.<commit_after>#if !defined(_IMAPSESSION_HPP_INCLUDED_)
#define _IMAPSESSION_HPP_INCLUDED_

#include <iostream>

#include <map>
#include <string>

#include <stdint.h>

#include <libcppserver/insensitive.hpp>
#include <libcppserver/internetsession.hpp>
#include <libcppserver/internetserver.hpp>
#include <libcppserver/sessiondriver.hpp>

#include "imapuser.hpp"
#include "namespace.hpp"
#include "sasl.hpp"
#include "mailsearch.hpp"
#include "mailmessage.hpp"

class ImapMaster;
class SessionDriver;
class MailSearch;
class MailMessage;

enum ImapState
  {
    ImapNotAuthenticated = 0,
    ImapAuthenticated,
    ImapSelected,
    ImapLogoff
  };

enum ImapStringState
  {
    ImapStringGood,
    ImapStringBad,
    ImapStringPending
  };

/*--------------------------------------------------------------------------------------*/
//* Imap											*/
/*--------------------------------------------------------------------------------------*/

class ImapSession;

typedef enum
  {
    IMAP_OK,
    IMAP_NO,
    IMAP_BAD,
    IMAP_NOTDONE,
    IMAP_NO_WITH_PAUSE,
    IMAP_MBOX_ERROR,
    IMAP_IN_LITERAL,
    IMAP_TRY_AGAIN
  } IMAP_RESULTS;

#define MAX_RESPONSE_STRING_LENGTH	80
#define IMAP_BUFFER_LEN			8192

typedef struct {
  bool levels[ImapLogoff+1];
  bool sendUpdatedStatus;
  // The flag is a bit of an odd duck.  It's here because I need to pass what essentially amounts to random bools to the
  // handler.  It means different things for different methods.
  // It distinguishes subscribe (flag = true) from unsubscribe (flag = false)
  // It distinguishes list (flag = true) from lsub (flag = false)
  // It distinguishes examine (flag = true) from select (flag = false)
  // It distinguishes uid (flag = true) from copy, close, search, fetch, and store (flag = false)
  bool flag;
  IMAP_RESULTS (ImapSession::*handler)(uint8_t *data, size_t dataLen, size_t &parsingAt, bool flag);
} symbol;

typedef std::map<insensitiveString, symbol> IMAPSYMBOLS;

class ImapSession : public InternetSession {
public:
  ImapSession(ImapMaster *master, SessionDriver *driver, InternetServer *server);
  virtual ~ImapSession();
  static void BuildSymbolTables(void);
  virtual void ReceiveData(uint8_t* pData, size_t dwDataLen );

  void AsynchronousEvent(void);
  ImapMaster *GetMaster(void) const { return m_master; }
  InternetServer *GetServer(void) const { return m_server; }
  SessionDriver *GetDriver(void) const { return m_driver; };
  time_t GetLastCommandTime() const { return m_lastCommandTime; }
  ImapState GetState(void) const { return m_state; }
  const ImapUser *GetUser(void) const { return m_userData; }
  // ReceiveData processes data as it comes it.  It's primary job is to chop the incoming data into
  // lines and to pass each line to HandleOneLine, which is the core command processor for the system
  void HandleOneLine(uint8_t *pData, size_t dwDataLen);
  void DoRetry(void);
  void IdleTimeout(void);

private:
  // These are configuration items
  bool m_LoginDisabled;
  static bool m_anonymousEnabled;
  unsigned m_failedLoginPause;
  SessionDriver *m_driver;
  MailStore::MAIL_STORE_RESULT m_mboxErrorCode;

  // These constitute the session's state
  enum ImapState m_state;
  IMAP_RESULTS (ImapSession::*m_currentHandler)(uint8_t *data, const size_t dataLen, size_t &parsingAt, bool flag);
{'fraction_non_alphanumeric': 0.13591507177033493, 'fraction_numerical': 0.0035885167464114833, 'mean_word_length': 3.537991858887381, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6562811', 'n_tokens_mistral': 2159, 'n_tokens_neox': 2091, 'n_words': 597}