1 // Copyright 2009 The Archiveopteryx Developers <info@aox.org>
2
3 #include "sieveaction.h"
4
5 #include "ustringlist.h"
6 #include "ustring.h"
7 #include "estring.h"
8
9
10 class SieveActionData
11 : public Garbage
12 {
13 public:
SieveActionData()14 SieveActionData()
15 : type( SieveAction::FileInto ),
16 mailbox( 0 ), flags( new UStringList ),
17 sender( 0 ), recipient( 0 ), message( 0 ),
18 expiry( 0 )
19 {}
20
21 SieveAction::Type type;
22 Mailbox * mailbox;
23 UStringList * flags;
24 Address * sender;
25 Address * recipient;
26 Injectee * message;
27 UString handle;
28 EString errorMessage;
29 uint expiry;
30 };
31
32
33 /*! \class SieveAction sieveaction.h
34
35 The SieveAction class models a single sieve action as specified in
36 RFC 5228 section 4, ie. something a SieveScript decides to do, and
37 that the Sieve interpreter does after sieving a message.
38
39 SieveAction objects are created by SieveCommand objects while
40 evaluating themselves in the context of a Message.
41 */
42
43
44
45 /*! Constructs a SieveAction of \a type. The constructed object is not
46 immediately valid; depending on \a type you may have to call
47 e.g. setMailbox().
48 */
49
SieveAction(Type type)50 SieveAction::SieveAction( Type type )
51 : Garbage(), d( new SieveActionData )
52 {
53 d->type = type;
54 }
55
56
57 /*! Returns the action's type, as set by the constructor. */
58
type() const59 SieveAction::Type SieveAction::type() const
60 {
61 return d->type;
62 }
63
64
65 /*! Records that this action's target is \a mailbox, provided that its
66 type() is FileInto. If type() has any other value, calling
67 setMailbox() sets an unused variable.
68 */
69
setMailbox(Mailbox * mailbox)70 void SieveAction::setMailbox( Mailbox * mailbox )
71 {
72 d->mailbox = mailbox;
73 }
74
75
76 /*! Returns the mailbox set by setMailbox(), or 0 if setMailbox() has
77 not been called. This value is only meaningful if type() is
78 FileInto.
79 */
80
mailbox() const81 Mailbox * SieveAction::mailbox() const
82 {
83 return d->mailbox;
84 }
85
86
87 /*! Records that this action's sender target is \a address, provided
88 that its type() is Redirect or Vacation. If type() has any other
89 value, calling setSenderAddress() sets an unused variable.
90 */
91
setSenderAddress(Address * address)92 void SieveAction::setSenderAddress( Address * address )
93 {
94 d->sender = address;
95 }
96
97
98 /*! Returns the address set by setSenderAddress(), or 0 if
99 setSenderAddress() has not been called.
100 */
101
senderAddress() const102 Address * SieveAction::senderAddress() const
103 {
104 return d->sender;
105 }
106
107
108 /*! Records that this action's recipient is \a address, provided that
109 its type() is Redirect or Vacation. If type() has any other value,
110 calling setRecipientAddress() sets an unused variable.
111 */
112
setRecipientAddress(Address * address)113 void SieveAction::setRecipientAddress( Address * address )
114 {
115 d->recipient = address;
116 }
117
118
119 /*! Returns the address set by setRecipientAddress(), or 0 if
120 setRecipientAddress() has not been called.
121 */
122
recipientAddress() const123 Address * SieveAction::recipientAddress() const
124 {
125 return d->recipient;
126 }
127
128
129 /*! Returns true if this action has finished its task, and false
130 otherwise.
131 */
132
done() const133 bool SieveAction::done() const
134 {
135 if ( failed() )
136 return true;
137 return false;
138 }
139
140
141 /*! Returns true if this action has failed to accomplish its task, and
142 false if it has succeeded or the possibility of success remains.
143 */
144
failed() const145 bool SieveAction::failed() const
146 {
147 return false;
148 }
149
150
151 /*! Records the error message \a m. Only useful if the action's type()
152 is Error.
153 */
154
setErrorMessage(const EString & m)155 void SieveAction::setErrorMessage( const EString & m )
156 {
157 d->errorMessage = m;
158 }
159
160
161 /*! Returns what setErrorMessage() recorded, or an empty string if
162 setErrorMessage() has not been called.
163 */
164
errorMessage() const165 EString SieveAction::errorMessage() const
166 {
167 return d->errorMessage;
168 }
169
170
171 /*! Records that the handle associated with this action is \a h. Only
172 useful for the Vacation type().
173 */
174
setHandle(const UString & h)175 void SieveAction::setHandle( const UString & h )
176 {
177 d->handle = h;
178 }
179
180
181 /*! Returns whatever setHandle() set, or an empty string if
182 setHandle() hasn't been called.
183 */
184
handle() const185 UString SieveAction::handle() const
186 {
187 return d->handle;
188 }
189
190
191 /*! Records that \a m is associated with this action. Only useful when
192 type() is Vacation.
193 */
194
setMessage(Injectee * m)195 void SieveAction::setMessage( Injectee * m )
196 {
197 d->message = m;
198 }
199
200
201 /*! Returns whatever setMessage() recorded, or a null pointer if
202 setMessage() hasn't been called.
203 */
204
message() const205 Injectee * SieveAction::message() const
206 {
207 return d->message;
208 }
209
210
211 /*! Records that this autoresponse should suppress similar
212 autoresponses for \a n days. Similarity is defined by handle(),
213 recipientAddress() and senderAddress().
214 */
215
setExpiry(uint n)216 void SieveAction::setExpiry( uint n )
217 {
218 d->expiry = n;
219 }
220
221
222 /*! Returns whatever setExpiry() recorded, or 0 if setExpiry() hasn't
223 been called.
224 */
225
expiry() const226 uint SieveAction::expiry() const
227 {
228 return d->expiry;
229 }
230
231
232 /*! Records that the message() should be stored into mailbox() using
233 \a flags.
234
235 The default is an empty list.
236 */
237
setFlags(const UStringList & flags)238 void SieveAction::setFlags( const UStringList & flags )
239 {
240 d->flags = new UStringList( flags );
241 }
242
243
244 /*! Returns a list containing all flags which will be used when
245 storing message() into mailbox().
246 */
247
flags() const248 UStringList * SieveAction::flags() const
249 {
250 return d->flags;
251 }
252