This file is indexed.

/usr/share/gosa/plugins/personal/mail/sieve/class_semantics.inc is in gosa-plugin-mail 2.7.4+reloaded2-9ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
<?php

class Semantics
{
	var $registerExtensionFn_;
	var $isExtensionRegisteredFn_;

	var $command_;
	var $comparator_;
	var $matchType_;
	var $s_;
	var $unknown;
	var $message;
	var $nonTestCommands_ = '(require|if|elsif|else|reject|fileinto|redirect|stop|keep|discard|mark|unmark|setflag|addflag|removeflag)';
	var $testsValidAfter_ = '(if|elsif|anyof|allof|not)';
	var $testCommands_ = '(address|envelope|header|size|allof|anyof|exists|not|true|false)';
	var $requireStrings_ = '(envelope|fileinto|reject|vacation|relational|subaddress|regex|imapflags|copy)';

	function Semantics($command)
	{
		$this->command_ = $command;
		$this->unknown = false;
		switch ($command)
		{

		/********************
		 * control commands
		 */
		case 'require':
			/* require <capabilities: string-list> */
			$this->s_ = array(
				'valid_after' => '(script-start|require)',
				'arguments' => array(
					array('class' => 'string', 'list' => true, 'name' => 'require-string', 'occurrences' => '1', 'call' => 'setRequire_', 'values' => array(
						array('occurrences' => '+', 'regex' => '"'. $this->requireStrings_ .'"'),
						array('occurrences' => '+', 'regex' => '"comparator-i;(octet|ascii-casemap|ascii-numeric)"')
					))
				)
			);
			break;

		case 'if':
			/* if <test> <block> */
			$this->s_ = array(
				'valid_after' => str_replace('(', '(script-start|', $this->nonTestCommands_),
				'arguments' => array(
					array('class' => 'identifier', 'occurrences' => '1', 'values' => array(
						array('occurrences' => '1', 'regex' => $this->testCommands_, 'name' => 'test')
					)),
					array('class' => 'block-start', 'occurrences' => '1', 'values' => array(
						array('occurrences' => '1', 'regex' => '{', 'name' => 'block')
					))
				)
			);
			break;

		case 'elsif':
			/* elsif <test> <block> */
			$this->s_ = array(
				'valid_after' => '(if|elsif)',
				'arguments' => array(
					array('class' => 'identifier', 'occurrences' => '1', 'values' => array(
						array('occurrences' => '1', 'regex' => $this->testCommands_, 'name' => 'test')
					)),
					array('class' => 'block-start', 'occurrences' => '1', 'values' => array(
						array('occurrences' => '1', 'regex' => '{', 'name' => 'block')
					))
				)
			);
			break;

		case 'else':
			/* else <block> */
			$this->s_ = array(
				'valid_after' => '(if|elsif)',
				'arguments' => array(
					array('class' => 'block-start', 'occurrences' => '1', 'values' => array(
						array('occurrences' => '1', 'regex' => '{', 'name' => 'block')
					))
				)
			);
			break;


		/*******************
		 * action commands
		 */
		case 'discard':
		case 'keep':
		case 'stop':
			/* discard / keep / stop */
			$this->s_ = array(
				'valid_after' => str_replace('(', '(script-start|', $this->nonTestCommands_)
			);
			break;

		case 'fileinto':
			/* fileinto [":copy"] <folder: string> */
			$this->s_ = array(
				'requires' => 'fileinto',
				'valid_after' => $this->nonTestCommands_,
				'arguments' => array(
					array('class' => 'tag', 'occurrences' => '?', 'values' => array(
						array('occurrences' => '?', 'regex' => ':copy', 'requires' => 'copy', 'name' => 'copy')
					)),
					array('class' => 'string', 'occurrences' => '1', 'values' => array(
						array('occurrences' => '1', 'regex' => '".*"', 'name' => 'folder')
					))
				)
			);
			break;

		case 'mark':
		case 'unmark':
			/* mark / unmark */
			$this->s_ = array(
				'requires' => 'imapflags',
				'valid_after' => $this->nonTestCommands_
			);
			break;

		case 'redirect':
			/* redirect [":copy"] <address: string> */
			$this->s_ = array(
				'valid_after' => str_replace('(', '(script-start|', $this->nonTestCommands_),
				'arguments' => array(
					array('class' => 'tag', 'occurrences' => '?', 'values' => array(
						array('occurrences' => '?', 'regex' => ':copy', 'requires' => 'copy', 'name' => 'size-type')
					)),
					array('class' => 'string', 'occurrences' => '1', 'values' => array(
						array('occurrences' => '1', 'regex' => '".*"', 'name' => 'address')
					))
				)
			);
			break;

		case 'reject':
			/* reject <reason: string> */
			$this->s_ = array(
				'requires' => 'reject',
				'valid_after' => $this->nonTestCommands_,
				'arguments' => array(
					array('class' => 'string', 'occurrences' => '1', 'values' => array(
						array('occurrences' => '1', 'regex' => '("|).*("|)', 'name' => 'reason')
					))
				)
			);
			break;

		case 'setflag':
		case 'addflag':
		case 'removeflag':
			/* setflag <flag-list: string-list> */
			/* addflag <flag-list: string-list> */
			/* removeflag <flag-list: string-list> */
			$this->s_ = array(
				'requires' => 'imapflags',
				'valid_after' =>$this->nonTestCommands_,
				'arguments' => array(
					array('class' => 'string', 'list' => true, 'occurrences' => '1', 'values' => array(
						array('occurrences' => '+', 'regex' => '".*"', 'name' => 'key')
					))
				)
			);
			break;

		case 'vacation':
			/* vacation [":days" number] [":addresses" string-list] [":subject" string] [":mime"] <reason: string> */
			$this->s_ = array(
				'requires' => 'vacation',
				'valid_after' => $this->nonTestCommands_,
				'arguments' => array(
					array('class' => 'tag', 'occurrences' => '*', 'values' => array(
						array('occurrences' => '?', 'regex' => ':days', 'name' => 'days',
							'add' => array(
								array('class' => 'number', 'occurrences' => '1', 'values' => array(
									array('occurrences' => '1', 'regex' => '.*', 'name' => 'period')
								))
							)
						),
						array('occurrences' => '?', 'regex' => ':addresses', 'name' => 'addresses',
							'add' => array(
								array('class' => 'string', 'list' => true, 'occurrences' => '1', 'values' => array(
									array('occurrences' => '+', 'regex' => '".*"', 'name' => 'address')
								))
							)
						),
						array('occurrences' => '?', 'regex' => ':subject', 'name' => 'subject',
							'add' => array(
								array('class' => 'string', 'occurrences' => '1', 'values' => array(
									array('occurrences' => '1', 'regex' => '".*"', 'name' => 'subject')
								))
							)
						),
						array('occurrences' => '?', 'regex' => ':mime', 'name' => 'mime')
					)),
					array('class' => 'string', 'occurrences' => '1', 'values' => array(
						array('occurrences' => '1', 'regex' => '.*', 'name' => 'reason')
					))
				)
			);
			break;


		/*****************
		 * test commands
		 */
		case 'address':
			/* address [address-part: tag] [comparator: tag] [match-type: tag] <header-list: string-list> <key-list: string-list> */
			$this->s_ = array(
				'valid_after' => $this->testsValidAfter_,
				'arguments' => array(
					array('class' => 'tag', 'occurrences' => '*', 'post-call' => 'checkTags_', 'values' => array(
						array('occurrences' => '?', 'regex' => ':(is|contains|matches|count|value|regex)', 'call' => 'setMatchType_', 'name' => 'match-type'),
						array('occurrences' => '?', 'regex' => ':(all|localpart|domain|user|detail)', 'call' => 'checkAddrPart_', 'name' => 'address-part'),
						array('occurrences' => '?', 'regex' => ':comparator', 'name' => 'comparator',
							'add' => array(
								array('class' => 'string', 'occurrences' => '1', 'call' => 'setComparator_', 'values' => array(
									array('occurrences' => '1', 'regex' => '"i;(octet|ascii-casemap)"', 'name' => 'comparator-string'),
									array('occurrences' => '1', 'regex' => '"i;ascii-numeric"', 'requires' => 'comparator-i;ascii-numeric', 'name' => 'comparator-string')
								))
							)
						)
					)),
					array('class' => 'string', 'list' => true, 'occurrences' => '1', 'values' => array(
						array('occurrences' => '+', 'regex' => '".*"', 'name' => 'header')
					)),
					array('class' => 'string', 'list' => true, 'occurrences' => '1', 'values' => array(
						array('occurrences' => '+', 'regex' => '".*"', 'name' => 'key')
					))
				)
			);
			break;

		case 'allof':
		case 'anyof':
			/* allof <tests: test-list>
			   anyof <tests: test-list> */
			$this->s_ = array(
				'valid_after' => $this->testsValidAfter_,
				'arguments' => array(
					array('class' => 'left-parant', 'occurrences' => '1', 'values' => array(
						array('occurrences' => '1', 'regex' => '\(', 'name' => 'test-list')
					)),
					array('class' => 'identifier', 'occurrences' => '+', 'values' => array(
						array('occurrences' => '+', 'regex' => $this->testCommands_, 'name' => 'test')
					))
				)
			);
			break;

		case 'envelope':
			/* envelope [address-part: tag] [comparator: tag] [match-type: tag] <envelope-part: string-list> <key-list: string-list> */
			$this->s_ = array(
				'requires' => 'envelope',
				'valid_after' => $this->testsValidAfter_,
				'arguments' => array(
					array('class' => 'tag', 'occurrences' => '*', 'post-call' => 'checkTags_', 'values' => array(
						array('occurrences' => '?', 'regex' => ':(is|contains|matches|count|value|regex)', 'call' => 'setMatchType_', 'name' => 'match-type'),
						array('occurrences' => '?', 'regex' => ':(all|localpart|domain|user|detail)', 'call' => 'checkAddrPart_', 'name' => 'address-part'),
						array('occurrences' => '?', 'regex' => ':comparator', 'name' => 'comparator',
							'add' => array(
								array('class' => 'string', 'occurrences' => '1', 'call' => 'setComparator_', 'values' => array(
									array('occurrences' => '1', 'regex' => '"i;(octet|ascii-casemap)"', 'name' => 'comparator-string'),
									array('occurrences' => '1', 'regex' => '"i;ascii-numeric"', 'requires' => 'comparator-i;ascii-numeric', 'name' => 'comparator-string')
								))
							)
						)
					)),
					array('class' => 'string', 'list' => true, 'occurrences' => '1', 'values' => array(
						array('occurrences' => '+', 'regex' => '".*"', 'name' => 'envelope-part')
					)),
					array('class' => 'string', 'list' => true, 'occurrences' => '1', 'values' => array(
						array('occurrences' => '+', 'regex' => '".*"', 'name' => 'key')
					))
				)
			);
			break;

		case 'exists':
			/* exists <header-names: string-list> */
			$this->s_ = array(
				'valid_after' => $this->testsValidAfter_,
				'arguments' => array(
					array('class' => 'string', 'list' => true, 'occurrences' => '1', 'values' => array(
						array('occurrences' => '+', 'regex' => '".*"', 'name' => 'header')
					))
				)
			);
			break;

		case 'header':
			/* header [comparator: tag] [match-type: tag] <header-names: string-list> <key-list: string-list> */
			$this->s_ = array(
				'valid_after' => $this->testsValidAfter_,
				'arguments' => array(
					array('class' => 'tag', 'occurrences' => '*', 'post-call' => 'checkTags_', 'values' => array(
						array('occurrences' => '?', 'regex' => ':(is|contains|matches|count|value|regex)', 'call' => 'setMatchType_', 'name' => 'match-type'),
						array('occurrences' => '?', 'regex' => ':comparator', 'name' => 'comparator',
							'add' => array(
								array('class' => 'string', 'occurrences' => '1', 'call' => 'setComparator_', 'values' => array(
									array('occurrences' => '1', 'regex' => '"i;(octet|ascii-casemap)"', 'name' => 'comparator-string'),
									array('occurrences' => '1', 'regex' => '"i;ascii-numeric"', 'requires' => 'comparator-i;ascii-numeric', 'name' => 'comparator-string')
								))
							)
						)
					)),
					array('class' => 'string', 'list' => true, 'occurrences' => '1', 'values' => array(
						array('occurrences' => '+', 'regex' => '".*"', 'name' => 'header')
					)),
					array('class' => 'string', 'list' => true, 'occurrences' => '1', 'values' => array(
						array('occurrences' => '+', 'regex' => '".*"', 'name' => 'key')
					))
				)
			);
			break;

		case 'not':
			/* not <test> */
			$this->s_ = array(
				'valid_after' => $this->testsValidAfter_,
				'arguments' => array(
					array('class' => 'identifier', 'occurrences' => '1', 'values' => array(
						array('occurrences' => '1', 'regex' => $this->testCommands_, 'name' => 'test')
					))
				)
			);
			break;

		case 'size':
			/* size <":over" / ":under"> <limit: number> */
			$this->s_ = array(
				'valid_after' => $this->testsValidAfter_,
				'arguments' => array(
					array('class' => 'tag', 'occurrences' => '1', 'values' => array(
						array('occurrences' => '1', 'regex' => ':(over|under)', 'name' => 'size-type')
					)),
					array('class' => 'number', 'occurrences' => '1', 'values' => array(
						array('occurrences' => '1', 'regex' => '.*', 'name' => 'limit')
					))
				)
			);
			break;

		case 'true':
		case 'false':
			/* true / false */
			$this->s_ = array(
				'valid_after' => $this->testsValidAfter_
			);
			break;


		/********************
		 * unknown commands
		 */
		default:
			$this->unknown = true;
		}
	}

	function setExtensionFuncs($setFn, $checkFn)
	{
		if (is_callable($setFn) && is_callable($checkFn))
		{
			$this->registerExtensionFn_ = $setFn;
			$this->isExtensionRegisteredFn_ = $checkFn;
		}
	}

	function setRequire_($extension)
	{
		call_user_func($this->registerExtensionFn_, $extension);
		return true;
	}

	function wasRequired_($extension)
	{
		return call_user_func($this->isExtensionRegisteredFn_, $extension);
	}

	function setMatchType_($text)
	{
		// Do special processing for relational test extension
		if ($text == ':count' || $text == ':value')
		{
			if (!$this->wasRequired_('relational'))
			{
				$this->message = 'missing require for match-type '. $text;
				return false;
			}

			array_unshift($this->s_['arguments'],
				array('class' => 'string', 'occurrences' => '1', 'values' => array(
					array('occurrences' => '1', 'regex' => '"(lt|le|eq|ge|gt|ne)"', 'name' => 'relation-string'),
				))
			);
		}
		// Do special processing for regex match-type extension
		else if ($text == ':regex' && !$this->wasRequired_('regex'))
		{
			$this->message = 'missing require for match-type '. $text;
			return false;
		}
		$this->matchType_ = $text;
		return true;
	}

	function setComparator_($text)
	{
		$this->comparator_ = $text;
		return true;
	}

	function checkAddrPart_($text)
	{
		if ($text == ':user' || $text == ':detail')
		{
			if (!$this->wasRequired_('subaddress'))
			{
				$this->message = 'missing require for tag '. $text;
				return false;
			}
		}
		return true;
	}

	function checkTags_()
	{
		if (isset($this->matchType_) &&
		    $this->matchType_ == ':count' &&
		    $this->comparator_ != '"i;ascii-numeric"')
		{
			$this->message = 'match-type :count needs comparator i;ascii-numeric';
			return false;
		}
		return true;
	}

	function validCommand($prev, $line)
	{
		// Check if command is known
		if ($this->unknown)
		{
			$this->message = 'line '. $line .': unknown command "'. $this->command_ .'"';
			return false;
		}

		// Check if the command needs to be required
		if (isset($this->s_['requires']) && !$this->wasRequired_($this->s_['requires']))
		{
			$this->message = 'line '. $line .': missing require for command "'. $this->command_ .'"';
			return false;
		}

		// Check if command may appear here
		if (strstr($prev, $this->s_['valid_after'] === false))
		{
#			$this->message = 'line '. $line .': "'. $this->command_ .'" may not appear after "'. $prev .'"';
#			return false;
		}

		return true;
	}

	function validClass_($class, $id)
	{
		// Check if command expects any arguments
		if (!isset($this->s_['arguments']))
		{
			$this->message = $id .' where semicolon expected';
			return false;
		}

		foreach ($this->s_['arguments'] as $arg)
		{
			if ($class == $arg['class'])
			{
				return true;
			}

			// Is the argument required
			if ($arg['occurrences'] != '?' && $arg['occurrences'] != '*')
			{
				$this->message = $id .' where '. $arg['class'] .' expected';
				return false;
			}

			if (isset($arg['post-call']) &&
				!call_user_func(array(&$this, $arg['post-call'])))
			{
				return false;
			}
			array_shift($this->s_['arguments']);
		}

		$this->message = 'unexpected '. $id;
		return false;
	}

	function startStringList($line)
	{
		if (!$this->validClass_('string', 'string'))
		{
			$this->message = 'line '. $line .': '. $this->message;
			return false;
		}
		else if (!isset($this->s_['arguments'][0]['list']))
		{
			$this->message = 'line '. $line .': '. 'left bracket where '. $this->s_['arguments'][0]['class'] .' expected';
			return false;
		}

		$this->s_['arguments'][0]['occurrences'] = '+';
		return true;
	}

	function endStringList()
	{
		array_shift($this->s_['arguments']);
	}

	function validToken($class, &$text, &$line)
	{
		$name = $class . ($class != $text ? " $text" : '');

		// Make sure the argument has a valid class
		if (!$this->validClass_($class, $name))
		{
			$this->message = 'line '. $line .': '. $this->message;
			return false;
		}

		$arg = &$this->s_['arguments'][0];
		foreach ($arg['values'] as $val)
		{
			if (preg_match('/^'. $val['regex'] .'$/m', $text))
			{
				// Check if the argument value needs a 'require'
				if (isset($val['requires']) && !$this->wasRequired_($val['requires']))
				{
					$this->message = 'line '. $line .': missing require for '. $val['name'] .' '. $text;
					return false;
				}

				// Check if a possible value of this argument may occur
				if ($val['occurrences'] == '?' || $val['occurrences'] == '1')
				{
					$val['occurrences'] = '0';
				}
				else if ($val['occurrences'] == '+')
				{
					$val['occurrences'] = '*';
				}
				else if ($val['occurrences'] == '0')
				{
					$this->message = 'line '. $line .': too many '. $val['name'] .' '. $class .'s near '. $text;
					return false;
				}

				// Call extra processing function if defined
				if (isset($val['call']) && !call_user_func(array(&$this, $val['call']), $text) ||
					isset($arg['call']) && !call_user_func(array(&$this, $arg['call']), $text))
				{
					$this->message = 'line '. $line .': '. $this->message;
					return false;
				}

				// Set occurrences appropriately
				if ($arg['occurrences'] == '?' || $arg['occurrences'] == '1')
				{
					array_shift($this->s_['arguments']);
				}
				else
				{
					$arg['occurrences'] = '*';
				}

				// Add argument(s) expected to follow right after this one
				if (isset($val['add']))
				{
					while ($add_arg = array_pop($val['add']))
					{
						array_unshift($this->s_['arguments'], $add_arg);
					}
				}

				return true;
			}
		}

		$this->message = 'line '. $line .': unexpected '. $name;
		return false;
	}

	function done($class, $text, $line)
	{
		if (isset($this->s_['arguments']))
		{
			foreach ($this->s_['arguments'] as $arg)
			{
				if ($arg['occurrences'] == '+' || $arg['occurrences'] == '1')
				{
					$this->message = 'line '. $line .': '. $class .' '. $text .' where '. $arg['class'] .' expected';
					return false;
				}
			}
		}
		return true;
	}
}

?>