7#include "vacationscriptextractor.h" 
   11using namespace KSieveCore;
 
   12VacationDataExtractor::VacationDataExtractor()
 
   15    qCDebug(LIBKSIEVECORE_LOG);
 
   18VacationDataExtractor::~VacationDataExtractor() = 
default;
 
   20void VacationDataExtractor::commandStart(
const QString &identifier, 
int lineNumber)
 
   22    qCDebug(LIBKSIEVECORE_LOG) << 
"(\"" << identifier << 
"\")";
 
   23    if (identifier == QLatin1StringView(
"if") && mContext == None) {
 
   25        mLineStart = lineNumber;
 
   29    if (commandFound() && (!mFoundInBlock || mBlockLevel > 0)) {
 
   30        if (identifier == QLatin1StringView(
"discard")) {
 
   31            mMailAction = VacationUtils::Discard;
 
   32        } 
else if (identifier == QLatin1StringView(
"redirect")) {
 
   33            mMailAction = VacationUtils::Sendto;
 
   34            mMailActionContext = RedirectCommand;
 
   38    if (identifier != QLatin1StringView(
"vacation")) {
 
   42    if (mContext != IfBlock) {
 
   43        mLineStart = lineNumber;
 
   47    mContext = VacationCommand;
 
   48    mFoundInBlock = (mBlockLevel > 0);
 
   51void VacationDataExtractor::commandEnd(
int lineNumber)
 
   53    qCDebug(LIBKSIEVECORE_LOG);
 
   54    if (mContext != None && mContext != IfBlock && mContext != VacationEnd) {
 
   55        mContext = VacationEnd;
 
   56        mLineEnd = lineNumber;
 
   58    mMailActionContext = None;
 
   61void VacationDataExtractor::error(
const KSieve::Error &e)
 
   63    qCDebug(LIBKSIEVECORE_LOG) << e.asString() << 
"@" << e.line() << 
"," << e.column();
 
   66void VacationDataExtractor::finished()
 
   70void VacationDataExtractor::testStart(
const QString &test)
 
   72    if (mContext == IfBlock) {
 
   73        if (test == QLatin1StringView(
"true") || test == QLatin1StringView(
"false")) {
 
   74            mActive = (
test == QLatin1StringView(
"true"));
 
   75            mIfComment = QString();
 
   80void VacationDataExtractor::hashComment(
const QString &comment)
 
   82    if (mContext == IfBlock) {
 
   83        mIfComment += comment;
 
   87void VacationDataExtractor::blockStart(
int lineNumber)
 
   93void VacationDataExtractor::blockEnd(
int lineNumber)
 
   96    if (mBlockLevel == 0 && !commandFound()) { 
 
   98        mIfComment = QString();
 
   99    } 
else if (mInIfBlock && mBlockLevel == 0 && commandFound()) {
 
  100        mLineEnd = lineNumber;
 
  105void VacationDataExtractor::taggedArgument(
const QString &tag)
 
  107    qCDebug(LIBKSIEVECORE_LOG) << 
"(\"" << tag << 
"\")";
 
  108    if (mMailActionContext == RedirectCommand) {
 
  109        if (tag == QLatin1StringView(
"copy")) {
 
  110            mMailAction = VacationUtils::CopyTo;
 
  113    if (mContext != VacationCommand) {
 
  116    if (tag == QLatin1StringView(
"days")) {
 
  118    } 
else if (tag == QLatin1StringView(
"addresses")) {
 
  119        mContext = Addresses;
 
  120    } 
else if (tag == QLatin1StringView(
"subject")) {
 
  125void VacationDataExtractor::stringArgument(
const QString &
string, 
bool, 
const QString &)
 
  127    qCDebug(LIBKSIEVECORE_LOG) << 
"(\"" << 
string << 
"\")";
 
  128    if (mContext == Addresses) {
 
  129        mAliases.push_back(
string);
 
  130        mContext = VacationCommand;
 
  131    } 
else if (mContext == Subject) {
 
  133        mContext = VacationCommand;
 
  134    } 
else if (mContext == VacationCommand) {
 
  135        mMessageText = string;
 
  136        mContext = VacationCommand;
 
  138    if (mMailActionContext == RedirectCommand) {
 
  139        mMailActionRecipient = string;
 
  143void VacationDataExtractor::numberArgument(
unsigned long number, 
char)
 
  145    qCDebug(LIBKSIEVECORE_LOG) << 
"(\"" << 
number << 
"\")";
 
  146    if (mContext != Days) {
 
  149    if (number > INT_MAX) {
 
  150        mNotificationInterval = INT_MAX;
 
  152        mNotificationInterval = 
number;
 
  154    mContext = VacationCommand;
 
  157void VacationDataExtractor::stringListArgumentStart()
 
  161void VacationDataExtractor::stringListEntry(
const QString &
string, 
bool, 
const QString &)
 
  163    qCDebug(LIBKSIEVECORE_LOG) << 
"(\"" << 
string << 
"\")";
 
  164    if (mContext != Addresses) {
 
  170void VacationDataExtractor::stringListArgumentEnd()
 
  172    qCDebug(LIBKSIEVECORE_LOG);
 
  173    if (mContext != Addresses) {
 
  176    mContext = VacationCommand;
 
  179void VacationDataExtractor::reset()
 
  181    qCDebug(LIBKSIEVECORE_LOG);
 
  183    mMailAction = VacationUtils::Keep;
 
  184    mMailActionRecipient = QString();
 
  185    mNotificationInterval = 0;
 
  187    mMessageText.clear();
 
  190RequireExtractor::RequireExtractor()
 
  191    : KSieve::ScriptBuilder()
 
  198RequireExtractor::~RequireExtractor() = 
default;
 
  200void RequireExtractor::commandStart(
const QString &identifier, 
int lineNumber)
 
  202    if (identifier == QLatin1StringView(
"require") && mContext == None) {
 
  203        mContext = RequireCommand;
 
  204        mLineStart = lineNumber;
 
  208void RequireExtractor::commandEnd(
int lineNumber)
 
  210    if (mContext == RequireCommand) {
 
  212        mLineEnd = lineNumber;
 
  216void RequireExtractor::error(
const KSieve::Error &e)
 
  218    qCDebug(LIBKSIEVECORE_LOG) << e.asString() << 
"@" << e.line() << 
"," << e.column();
 
  221void RequireExtractor::finished()
 
  225void RequireExtractor::stringArgument(
const QString &
string, 
bool, 
const QString &)
 
  227    mRequirements << string;
 
  230void RequireExtractor::stringListEntry(
const QString &
string, 
bool, 
const QString &)
 
  232    mRequirements << string;
 
KIOCORE_EXPORT QString number(KIO::filesize_t size)