~ubuntu-branches/ubuntu/quantal/kdepim/quantal

« back to all changes in this revision

Viewing changes to mailcommon/searchpattern.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Kolberg
  • Date: 2011-09-03 13:01:43 UTC
  • mfrom: (0.2.14)
  • Revision ID: package-import@ubuntu.com-20110903130143-5mmx3goibh8sgt9t
Tags: 4:4.7.1-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
#include <kdebug.h>
48
48
#include <kconfig.h>
49
49
#include <kconfiggroup.h>
 
50
#include <kascii.h>
50
51
 
51
52
#include <kmime/kmime_message.h>
52
53
#include <kmime/kmime_util.h>
130
131
                                                const QString & contents )
131
132
{
132
133
  SearchRule::Ptr ret;
133
 
  if (field == "<status>")
 
134
  if (field == "<status>" )
134
135
    ret = SearchRule::Ptr( new SearchRuleStatus( field, func, contents ) );
135
136
  else if ( field == "<age in days>" || field == "<size>" )
136
137
    ret = SearchRule::Ptr( new SearchRuleNumerical( field, func, contents ) );
409
410
  // Overwrite the value for complete messages and all headers!
410
411
  bool logContents = true;
411
412
 
412
 
  if( field() == "<message>" ) {
 
413
  if( kasciistricmp( field(), "<message>" ) == 0 ) {
413
414
    msgContents = msg->encodedContent();
414
415
    logContents = false;
415
 
  } else if ( field() == "<body>" ) {
 
416
  } else if ( kasciistricmp( field(), "<body>" ) == 0 ) {
416
417
    msgContents = msg->body();
417
418
    logContents = false;
418
 
  } else if ( field() == "<any header>" ) {
 
419
  } else if ( kasciistricmp( field(), "<any header>" ) == 0 ) {
419
420
    msgContents = msg->head();
420
421
    logContents = false;
421
 
  } else if ( field() == "<recipients>" ) {
 
422
  } else if ( kasciistricmp( field(), "<recipients>" ) == 0 ) {
422
423
    // (mmutz 2001-11-05) hack to fix "<recipients> !contains foo" to
423
424
    // meet user's expectations. See FAQ entry in KDE 2.2.2's KMail
424
425
    // handbook
432
433
    msgContents = msg->to()->asUnicodeString();
433
434
    msgContents += ", " + msg->cc()->asUnicodeString();
434
435
    msgContents += ", " + msg->bcc()->asUnicodeString();
435
 
  } else if ( field() == "<tag>" ) {
 
436
  } else if ( kasciistricmp( field(), "<tag>" ) == 0) {
436
437
#ifndef KDEPIM_NO_NEPOMUK    
437
438
    const Nepomuk::Resource res( item.url() );
438
439
    foreach ( const Nepomuk::Tag &tag, res.tags() )
485
486
void SearchRuleString::addQueryTerms(Nepomuk::Query::GroupTerm& groupTerm) const
486
487
{
487
488
  Nepomuk::Query::OrTerm termGroup;
488
 
  if ( field().toLower() == "to" || field() == "<recipients>" || field() == "<any header>" || field() == "<message>" )
 
489
  if ( kasciistricmp( field(), "<message>" ) == 0 || kasciistricmp( field(), "<recipients>" ) ==0  || kasciistricmp( field(), "<any header>" ) == 0 ) {
 
490
    const Nepomuk::Query::ComparisonTerm valueTerm( Vocabulary::NCO::emailAddress(), Nepomuk::Query::LiteralTerm( contents() ), nepomukComparator() );
 
491
    const Nepomuk::Query::ComparisonTerm addressTerm( Vocabulary::NCO::hasEmailAddress(), valueTerm, Nepomuk::Query::ComparisonTerm::Equal );
 
492
    const Nepomuk::Query::ComparisonTerm personTerm( Vocabulary::NMO::to(), addressTerm, Nepomuk::Query::ComparisonTerm::Equal );
 
493
    const Nepomuk::Query::ComparisonTerm personTermTo( Vocabulary::NMO::cc(), personTerm, Nepomuk::Query::ComparisonTerm::Equal );
 
494
    const Nepomuk::Query::ComparisonTerm personTermCC( Vocabulary::NMO::bcc(), personTermTo, Nepomuk::Query::ComparisonTerm::Equal );
 
495
 
 
496
    if ( kasciistricmp( field(), "<any header>" ) == 0 ) {
 
497
      const Nepomuk::Query::ComparisonTerm personTermBCC( Vocabulary::NMO::from(), personTermTo, Nepomuk::Query::ComparisonTerm::Equal );
 
498
      termGroup.addSubTerm( personTermBCC );
 
499
    }
 
500
    else
 
501
      termGroup.addSubTerm( personTermCC );
 
502
  }
 
503
  
 
504
  if ( kasciistricmp( field(), "to" ) == 0 )
489
505
    addPersonTerm( termGroup, Vocabulary::NMO::to() );
490
 
  if ( field().toLower() == "cc" || field() == "<recipients>" || field() == "<any header>" || field() == "<message>" )
 
506
  else if ( kasciistricmp( field(), "cc" ) == 0 )
491
507
    addPersonTerm( termGroup, Vocabulary::NMO::cc() );
492
 
  if ( field().toLower() == "bcc" || field() == "<recipients>" || field() == "<any header>" || field() == "<message>" )
 
508
  else if ( kasciistricmp( field(), "bcc" ) == 0 )
493
509
    addPersonTerm( termGroup, Vocabulary::NMO::bcc() );
494
 
 
495
 
  if ( field().toLower() == "from" || field() == "<any header>" || field() == "<message>" )
 
510
  else if ( kasciistricmp( field(), "from" ) == 0 )
496
511
    addPersonTerm( termGroup, Vocabulary::NMO::from() );
497
 
 
498
 
  if ( field().toLower() == "subject" || field() == "<any header>" || field() == "<message>" ) {
 
512
  
 
513
  if ( kasciistricmp( field(), "subject" ) == 0 || kasciistricmp( field(), "<any header>" ) == 0 || kasciistricmp( field(), "<message>" ) == 0 ) {
499
514
    const Nepomuk::Query::ComparisonTerm subjectTerm( Vocabulary::NMO::messageSubject(), Nepomuk::Query::LiteralTerm( contents() ), nepomukComparator() );
500
515
    termGroup.addSubTerm( subjectTerm );
501
516
  }
 
517
  if ( kasciistricmp( field(), "reply-to" ) == 0 ) {
 
518
    const Nepomuk::Query::ComparisonTerm replyToTerm( Vocabulary::NMO::messageReplyTo(), Nepomuk::Query::LiteralTerm( contents() ), nepomukComparator() );
 
519
    termGroup.addSubTerm( replyToTerm );
 
520
  }
502
521
 
 
522
  if ( kasciistricmp( field(), "list-id" ) == 0 ) {
 
523
    //TODO
 
524
  }
 
525
  else if ( kasciistricmp( field(), "resent-from" ) == 0 ) {
 
526
    //TODO
 
527
  }
 
528
  else if ( kasciistricmp( field(), "x-loop" ) == 0 ) {
 
529
    //TODO
 
530
  }
 
531
  else if ( kasciistricmp( field(), "x-mailing-list" ) == 0 ) {
 
532
    //TODO
 
533
  }
 
534
  else if ( kasciistricmp( field(), "x-spam-flag" ) == 0 ) {
 
535
    //TODO
 
536
  }
 
537
  
503
538
  // TODO complete for other headers, generic headers
504
539
 
505
 
  if ( field() == "<tag>" ) {
 
540
  if ( kasciistricmp( field(), "organization" )  == 0 ) {
 
541
      const Nepomuk::Query::ComparisonTerm headerTerm( Vocabulary::NMO::headerName(), Nepomuk::Query::LiteralTerm( contents() ), nepomukComparator() );
 
542
    termGroup.addSubTerm( headerTerm );
 
543
  //TODO
 
544
  }
 
545
 
 
546
 
 
547
  if ( kasciistricmp( field(), "<tag>" ) == 0 ) {
506
548
    const Nepomuk::Tag tag( contents() );
507
549
    addAndNegateTerm( Nepomuk::Query::ComparisonTerm( Soprano::Vocabulary::NAO::hasTag(),
508
550
                                                      Nepomuk::Query::ResourceTerm( tag ),
513
555
  if ( field() == "<body>" || field() == "<message>" ) {
514
556
    const Nepomuk::Query::ComparisonTerm bodyTerm( Vocabulary::NMO::plainTextMessageContent(), Nepomuk::Query::LiteralTerm( contents() ), nepomukComparator() );
515
557
    termGroup.addSubTerm( bodyTerm );
516
 
 
517
558
    const Nepomuk::Query::ComparisonTerm attachmentBodyTerm( Vocabulary::NMO::plainTextMessageContent(), Nepomuk::Query::LiteralTerm( contents() ), nepomukComparator() );
518
559
    const Nepomuk::Query::ComparisonTerm attachmentTerm( Vocabulary::NIE::isPartOf(), attachmentBodyTerm, Nepomuk::Query::ComparisonTerm::Equal );
519
560
    termGroup.addSubTerm( attachmentTerm );
643
684
 
644
685
  stream.writeStartElement( func );
645
686
 
646
 
  if ( field().toLower() == "subject" ||
647
 
       field().toLower() == "to" ||
648
 
       field().toLower() == "cc" ||
649
 
       field().toLower() == "bcc" ||
650
 
       field().toLower() == "from" ||
651
 
       field().toLower() == "sender" ) {
 
687
  if ( field().toLower() == "subject"  ||
 
688
       field().toLower() == "to"  ||
 
689
       field().toLower() == "cc"  ||
 
690
       field().toLower() == "bcc"  ||
 
691
       field().toLower() == "from"  ||
 
692
       field().toLower() == "sender"  ) {
652
693
    stream.writeStartElement( QLatin1String("field") );
653
694
    stream.writeAttribute( QLatin1String("name"), field().toLower() );
654
695
  } else {
690
731
  qint64 numericalMsgContents = 0;
691
732
  qint64 numericalValue = 0;
692
733
 
693
 
  if ( field() == "<size>" ) {
 
734
  if ( kasciistricmp( field(), "<size>" ) == 0 ) {
694
735
    numericalMsgContents = item.size();
695
736
    numericalValue = contents().toLongLong();
696
737
    msgContents.setNum( numericalMsgContents );
697
 
  } else if ( field() == "<age in days>" ) {
 
738
  } else if ( kasciistricmp( field(), "<age in days>" ) == 0 ) {
698
739
    QDateTime msgDateTime = msg->date()->dateTime().dateTime();
699
740
    numericalMsgContents = msgDateTime.daysTo( QDateTime::currentDateTime() );
700
741
    numericalValue = contents().toInt();
768
809
 
769
810
void SearchRuleNumerical::addQueryTerms(Nepomuk::Query::GroupTerm& groupTerm) const
770
811
{
771
 
  if ( field() == "<size>" ) {
 
812
  if ( kasciistricmp( field() , "<size>" ) == 0 ) {
772
813
    const Nepomuk::Query::ComparisonTerm sizeTerm( Vocabulary::NIE::byteSize(),
773
814
                                                   Nepomuk::Query::LiteralTerm( contents().toInt() ),
774
815
                                                   nepomukComparator() );
775
816
    addAndNegateTerm( sizeTerm, groupTerm );
776
 
  } else if ( field() == "<age in days>" ) {
777
 
    kDebug() << "AKONADI PORT: Disabled code in  " << Q_FUNC_INFO;
778
 
    // TODO
 
817
  } else if ( kasciistricmp( field(), "<age in days>" ) == 0 ) {
 
818
    QDate date = QDate::currentDate();
 
819
    date = date.addDays( contents().toInt() );
 
820
    const Nepomuk::Query::ComparisonTerm dateTerm( Vocabulary::NMO::sentDate(),Nepomuk::Query::LiteralTerm(date ),nepomukComparator() );
 
821
    addAndNegateTerm( dateTerm, groupTerm );
779
822
  }
780
823
}
781
824
#endif
793
836
//==================================================
794
837
QString englishNameForStatus( const Akonadi::MessageStatus &status )
795
838
{
796
 
  for ( int i=0; i< numStatusNames; i++ ) {
 
839
  for ( int i=0; i< numStatusNames; ++i ) {
797
840
    if ( statusNames[i].status == status ) {
798
841
      return statusNames[i].name;
799
842
    }
818
861
 
819
862
Akonadi::MessageStatus SearchRuleStatus::statusFromEnglishName( const QString &aStatusString )
820
863
{
821
 
  for ( int i=0; i< numStatusNames; i++ ) {
 
864
  for ( int i=0; i< numStatusNames; ++i ) {
822
865
    if ( !aStatusString.compare( statusNames[i].name ) ) {
823
866
      return statusNames[i].status;
824
867
    }