summaryrefslogtreecommitdiffstats
path: root/kshowmail/filterlogentry.cpp
blob: 8928b912a83c65598e7a7056c7d6dba65f91ff85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145


//
// C++ Implementation: filterlogentry
//
// Description:
//
//
// Author: Ulrich Weigelt <ulrich.weigelt@gmx.de>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "filterlogentry.h"

FilterLogEntry::FilterLogEntry()
{
  //set default values
  sentDateTime.setDate( TQDate( 2007, 11, 7 ) );
  sentDateTime.setTime( TQTime( 19, 05 ) );
  act = FActNone;
}

FilterLogEntry::FilterLogEntry( FilterAction_Type action, const TQDateTime& dateTime, const TQString& sender, const TQString& account, const TQString& subject, const TQString& mailbox)
  : act( action ), sentDateTime( dateTime ), sender( sender ), account( account ), subject( subject ), mailbox( mailbox )
{
}

FilterLogEntry::~FilterLogEntry()
{
}

void FilterLogEntry::print()
{
  TQString strAction;
  switch( act )
  {
    case FActPass       : strAction = "Passed"; break;
    case FActDelete     : strAction = "Deleted"; break;
    case FActMark       : strAction = "Marked"; break;
    case FActSpamcheck  : strAction = "forwarded to check for spam"; break;
    case FActMove       : strAction = TQString( "moved to %1" ).arg( mailbox); break;
    case FActNone       : strAction = "no Action (THIS IS AN ERROR!)"; break;
    default             : strAction = "ERROR! UNKNOWN ACTION"; break;
  }

  kdDebug() << sentDateTime.toString( TQt::LocalDate ) << ";" << account << ";" << sender << ";" << subject << ";" << strAction << endl;
}

FilterLogEntry::FilterLogEntry(const FilterLogEntry & ent)
{
  this->sentDateTime = ent.sentDateTime;
  this->account = ent.account;
  this->sender = ent.sender;
  this->subject = ent.subject;
  this->act = ent.act;
  this->mailbox = ent.mailbox;
}

FilterLogEntry& FilterLogEntry::operator=( const FilterLogEntry & ent )
{
  if( this == &ent ) return *this;

  this->sentDateTime = ent.sentDateTime;
  this->account = ent.account;
  this->sender = ent.sender;
  this->subject = ent.subject;
  this->mailbox = ent.mailbox;
  this->act = ent.act;

  return *this;
}

bool FilterLogEntry::isOlder( uint days )
{
  return sentDateTime.date().addDays( days ) < TQDate::currentDate();
}

bool FilterLogEntry::operator== ( const FilterLogEntry& ent ) const
{
  return sentDateTime == ent.sentDateTime;
}

bool FilterLogEntry::operator!=( const FilterLogEntry& ent ) const
{
  return sentDateTime != ent.sentDateTime;
}

bool FilterLogEntry::operator>( const FilterLogEntry& ent ) const
{
  return sentDateTime > ent.sentDateTime;
}

bool FilterLogEntry::operator>=( const FilterLogEntry& ent ) const
{
  return sentDateTime >= ent.sentDateTime;
}

bool FilterLogEntry::operator<( const FilterLogEntry& ent ) const
{
  return sentDateTime < ent.sentDateTime;
}

bool FilterLogEntry::operator<=( const FilterLogEntry & ent ) const
{
  return sentDateTime <= ent.sentDateTime;
}

void FilterLogEntry::save( TQDomDocument& doc, TQDomElement& parent )
{
  //create a new element and store the entry
  TQDomElement elem = doc.createElement( LOG_ENTRY_ELEMENT );
  elem.setAttribute( LOG_ENTRY_ATTRIBUTE_DATETIME, sentDateTime.toString( TQt::ISODate) );
  elem.setAttribute( LOG_ENTRY_ATTRIBUTE_SENDER, sender );
  elem.setAttribute( LOG_ENTRY_ATTRIBUTE_ACCOUNT, account );
  elem.setAttribute( LOG_ENTRY_ATTRIBUTE_SUBJECT, subject );

  //add entry element to the log (parent) element
  parent.appendChild( elem );
}

TQDateTime FilterLogEntry::getDate( )
{
  return sentDateTime;
}

TQString FilterLogEntry::getSender( )
{
  return sender;
}

TQString FilterLogEntry::getAccount( )
{
  return account;
}

TQString FilterLogEntry::getSubject( )
{
  return subject;
}

TQString FilterLogEntry::getMailbox( )
{
  return mailbox;
}