<commit_before>/*  -*- c++ -*-
    vacation.cpp

    KMail, the KDE mail client.
    Copyright (c) 2002 <NAME> <<EMAIL>>

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License,
    version 2.0, as published by the Free Software Foundation.
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
*/

#include "vacation.h"

#include "vacationdialog.h"
#include "sievejob.h"
using KMail::SieveJob;
#include "sieveconfig.h"
#include "kmkernel.h"
#include "kmacctmgr.h"
#include "kmacctimap.h"

#include <kglobal.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kdebug.h>

#include <qregexp.h>
#include <qdatetime.h>
#include <qstring.h>
#include <qtimer.h>

#include <cassert>

namespace KMail {

  Vacation::Vacation( QObject * parent, const char * name )
    : QObject( parent, name ), mSieveJob( 0 ), mDialog( 0 )
  {
    mUrl = findURL();
    kdDebug() << "Vacation: found url \"" << mUrl.url() << "\"" << endl;
    if ( mUrl.isEmpty() ) // nothing to do...
      return;
    mUrl.setFileName( "kmail-vacation.siv" );
    mSieveJob = SieveJob::get( mUrl );
    connect( mSieveJob, SIGNAL(result(KMail::SieveJob*,bool,const QString&,bool)),
	     SLOT(slotGetResult(KMail::SieveJob*,bool,const QString&,bool)) );
  }

  Vacation::~Vacation() {
    if ( mSieveJob ) mSieveJob->kill();
    delete mDialog;
    kdDebug() << "~Vacation()" << endl;
  }

  QString Vacation::composeScript( const QDate & returnDate, int notificationInterval ) {
    QString script
      = QString::fromLatin1("require \"vacation\";\r\n"
			    "# keep next two lines:\r\n"
			    // if you change these lines, change parseScript, too!
			    "# return date: %1\r\n"
			    "# notification interval: %2\r\n"
			    "vacation ").arg( returnDate.toString( ISODate ) )
                                        .arg( notificationInterval );
    if ( notificationInterval > 0 )
      script += QString::fromLatin1(":days %1 ").arg( notificationInterval );
    script += QString::fromLatin1("text:\r\n");
    script += i18n("<EMAIL>: If your translation results in a line "
		   "beginning with a dot (.), escape it by prepending another "
		   "dot. Keep the trailing line with the single dot!",
		   "This is to inform you that I'm out of office until %1.\r\n"
		   ".\r\n"
		   ";\r\n").arg( KGlobal::locale()->formatDate( returnDate ) );
    return script;
  }

  static KURL findUrlForAccount( const KMAcctImap * a ) {
    assert( a );
    SieveConfig sieve = a->sieveConfig();
    if ( !sieve.managesieveSupported() )
      return KURL();
    if ( sieve.reuseConfig() ) {
      // assemble Sieve url from the settings of the account:
      KURL u;
      u.setProtocol( "sieve" );
      u.setHost( a->host() );
      u.setUser( a->login() );
      u.setPass( a->passwd() );
      u.setPort( sieve.port() );
      return u;
    } else {
      return sieve.alternateURL();
    }
  }

  KURL Vacation::findURL() const {
    KMAcctMgr * am = kernel->acctMgr();
    assert( am );
    for ( KMAccount * a = am->first() ; a ; a = am->next() )
      if ( dynamic_cast<KMAcctImap*>(a) ) {
	KURL u = findUrlForAccount( static_cast<KMAcctImap*>(a) );
	if ( !u.isEmpty() )
	  return u;
      }
    return KURL();
  }

  bool Vacation::parseScript( const QString & script, QDate & returnDate,
			      int & notificationInterval ) {
    if ( script.isEmpty() ) {
      returnDate = defaultReturnDate();
      notificationInterval = defaultNotificationInterval();
      return true;
    }
    // extract the data from the comments we added in composeScript():
    QRegExp rx("#\\s*return\\s+date:\\s*(\\d{4}-\\d{2}-\\d{2}).*"
	       "#\\s*notification\\s+interval:\\s*(-?\\d+)", false );
    if ( rx.search( script, 0 ) != -1 ) {
      // found
      returnDate = QDate::fromString( rx.cap(1), ISODate );
      notificationInterval = rx.cap(2).toInt();
      return true;
    }
    return false;
  };<commit_msg>Vacation support for all! (i.e. also for cachedimap :)<commit_after>/*  -*- c++ -*-
    vacation.cpp

    KMail, the KDE mail client.
    Copyright (c) 2002 <NAME> <<EMAIL>>

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License,
    version 2.0, as published by the Free Software Foundation.
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
*/

#include "vacation.h"

#include "vacationdialog.h"
#include "sievejob.h"
using KMail::SieveJob;
#include "sieveconfig.h"
#include "kmkernel.h"
#include "kmacctmgr.h"
#include "kmacctimap.h"

#include <kglobal.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kdebug.h>

#include <qregexp.h>
#include <qdatetime.h>
#include <qstring.h>
#include <qtimer.h>

#include <cassert>

namespace KMail {

  Vacation::Vacation( QObject * parent, const char * name )
    : QObject( parent, name ), mSieveJob( 0 ), mDialog( 0 )
  {
    mUrl = findURL();
    kdDebug() << "Vacation: found url \"" << mUrl.url() << "\"" << endl;
    if ( mUrl.isEmpty() ) // nothing to do...
      return;
    mUrl.setFileName( "kmail-vacation.siv" );
    mSieveJob = SieveJob::get( mUrl );
    connect( mSieveJob, SIGNAL(result(KMail::SieveJob*,bool,const QString&,bool)),
	     SLOT(slotGetResult(KMail::SieveJob*,bool,const QString&,bool)) );
  }

  Vacation::~Vacation() {
    if ( mSieveJob ) mSieveJob->kill();
    delete mDialog;
    kdDebug() << "~Vacation()" << endl;
  }

  QString Vacation::composeScript( const QDate & returnDate, int notificationInterval ) {
    QString script
      = QString::fromLatin1("require \"vacation\";\r\n"
			    "# keep next two lines:\r\n"
			    // if you change these lines, change parseScript, too!
			    "# return date: %1\r\n"
			    "# notification interval: %2\r\n"
			    "vacation ").arg( returnDate.toString( ISODate ) )
                                        .arg( notificationInterval );
    if ( notificationInterval > 0 )
      script += QString::fromLatin1(":days %1 ").arg( notificationInterval );
    script += QString::fromLatin1("text:\r\n");
    script += i18n("<EMAIL>: If your translation results in a line "
		   "beginning with a dot (.), escape it by prepending another "
		   "dot. Keep the trailing line with the single dot!",
		   "This is to inform you that I'm out of office until %1.\r\n"
		   ".\r\n"
		   ";\r\n").arg( KGlobal::locale()->formatDate( returnDate ) );
    return script;
  }

  static KURL findUrlForAccount( const KMail::ImapAccountBase * a ) {
    assert( a );
    SieveConfig sieve = a->sieveConfig();
    if ( !sieve.managesieveSupported() )
      return KURL();
    if ( sieve.reuseConfig() ) {
      // assemble Sieve url from the settings of the account:
      KURL u;
      u.setProtocol( "sieve" );
      u.setHost( a->host() );
      u.setUser( a->login() );
      u.setPass( a->passwd() );
      u.setPort( sieve.port() );
      return u;
    } else {
      return sieve.alternateURL();
    }
  }

  KURL Vacation::findURL() const {
    KMAcctMgr * am = kernel->acctMgr();
    assert( am );
    for ( KMAccount * a = am->first() ; a ; a = am->next() )
      if ( dynamic_cast<KMail::ImapAccountBase*>(a) ) {
	KURL u = findUrlForAccount( static_cast<KMail::ImapAccountBase*>(a) );
	if ( !u.isEmpty() )
	  return u;
      }
    return KURL();
  }

  bool Vacation::parseScript( const QString & script, QDate & returnDate,
			      int & notificationInterval ) {
    if ( script.isEmpty() ) {
      returnDate = defaultReturnDate();
      notificationInterval = defaultNotificationInterval();
      return true;
    }
    // extract the data from the comments we added in composeScript():
    QRegExp rx("#\\s*return\\s+date:\\s*(\\d{4}-\\d{2}-\\d{2}).*"
	       "#\\s*notification\\s+interval:\\s*(-?\\d+)", false );
    if ( rx.search( script, 0 ) != -1 ) {
      // found
      returnDate = QDate::fromString( rx.cap(1), ISODate );
      notificationInterval = rx.cap(2).toInt();
      return true;
    }
    return false;
  };
{'fraction_non_alphanumeric': 0.15316074653822997, 'fraction_numerical': 0.009391932570740518, 'mean_word_length': 2.8329487771112136, 'pattern_counts': {'":': 2, '<': 57, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3554966', 'n_tokens_mistral': 2897, 'n_tokens_neox': 2766, 'n_words': 742}