summaryrefslogtreecommitdiff
path: root/src/plugins/maildir.php
blob: 28211b5e19a611dc6a34bb067a79147dd28da250 (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
<?php
require_once('Getter.class.php');
////////////////////////////////////////////////////////////////////////////////
class Maildir implements Getter {
	private $config = array('dir'=>'');
	
	public function configList() {
		return array('dir'=>'text');
	}
	
	public function init() {}
	
	public function get() {
		$this->handle_new();
		$this->handle_cur();
		$this->handle_tmp();
	}
	
	private function handle_new() {
		// move files in new to cur
		$new = $this->config['dir'].'/new';
		$cur = $this->config['dir'].'/cur';
		$dh = opendir($new);
		
		while (($file = readdir($dh)) !== false) {
			if (substr($file,0,1)!='.' && is_file($new.'/'.$file)) {
				rename($new.'/'.$file,
				       $cur.'/'.$file.':');
			}
		}
	}
	private function handle_cur() {
		$cur = $this->config['dir'].'/cur';
		$dh = opendir($cur);
		
		while (($file = readdir($dh)) !== false) {
			if (substr($file,0,1)!='.' && is_file($cur.'/'.$file)) {
				
			}
		}
	}
	private function handle_tmp() {
		// Clean up files that haven't been accessed for 36 hours
		$tmp = $this->config['dir'].'/tmp';
		$dh = opendir($cur);
		
		while (($file = readdir($dh)) !== false) {
			if (is_file($tmp.'/'.$file)) {
				$atime = fileatime($tmp.'/'.$file);
				$time = time();
				if (($time-$atime)>(36*60*60)) {
					unlink($tmp.'/'.$file);
				}
			}
		}
	}

}