-
Notifications
You must be signed in to change notification settings - Fork 0
/
junk_report.php
185 lines (161 loc) · 5.84 KB
/
junk_report.php
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
<?php
/**
* Junk Report
*
* Send periodically an email to each mailbox with the list of messages in their junk directory
*
* @version 1.0
* @author IRCF
* @url https://github.com/ircf/junk_report
*/
class junk_report extends rcube_plugin
{
public $task = 'mail|settings';
private $user;
private $prefs;
private $rcmail;
function init()
{
$this->rcmail = rcmail::get_instance();
$this->user = $this->rcmail->user;
$this->prefs = $this->user->get_prefs();
$this->load_config();
$this->add_texts('localization/', true);
$this->require_plugin('markasjunk2');
$this->register_action('plugin.junk_report', array($this, 'show'));
$this->register_action('plugin.junk_report.show', array($this, 'show'));
$this->register_action('plugin.junk_report.save', array($this, 'save'));
$this->register_action('plugin.junk_report.not_junk', array($this, 'not_junk'));
$this->register_action('plugin.junk_report.cron', array($this, 'cron'));
$this->add_hook('settings_actions', array($this, 'settings_actions'));
}
/**
* add settings tab
*/
function settings_actions($args)
{
$args['actions'][] = array(
'action' => 'plugin.junk_report.show',
'class' => 'junk_report',
'label' => 'title',
'domain' => 'junk_report',
);
return $args;
}
/**
* display settings form
*/
function show()
{
$this->register_handler('plugin.body', array($this, 'show_body'));
$this->rcmail->output->set_pagetitle($this->gettext('title'));
$this->rcmail->output->send('plugin');
}
function show_body()
{
//read from user preferences
if (!(isset($this->prefs["frequency"]) && isset($this->prefs["maxlength"]))) {
$frequency = $config['default_frequency'];
$maxlength = $config['default_maxlength'];
} else {
$frequency = $this->prefs["frequency"];
$maxlength = $this->prefs["maxlength"];
}
$table = new html_table(array('cols' => 2, 'class' => 'propform'));
$table->add('title', html::label('', $this->gettext('frequency')));
$select = new html_select(array('name' => '_frequency'));
$select->add($this->gettext('never'), 'never');
$select->add($this->gettext('daily'), 'daily');
$select->add($this->gettext('weekly'), 'weekly');
$select->add($this->gettext('monthly'), 'monthly');
$table->add('', $select->show($frequency));
$table->add('title', html::label('', $this->gettext('maxlength')));
$table->add('', html::tag('input', array(
'type' => 'number',
'name' => '_maxlength',
'value' => $maxlength,
'min' => 1,
'max' => $config['default_maxlength'],
'required' => true
)));
return html::tag('form', array(
'action' => $this->rcmail->url('plugin.junk_report.save'),
'method' => 'post'
),
html::div(array('class' => 'box formcontent'),
html::div(array('class' => 'boxtitle'), $this->gettext('title'))
. html::div(array('class' => 'boxcontent'),
html::p('', $this->gettext('description'))
. '<br>'
. $table->show()
. html::p(array('class' => 'formbuttons'),
html::tag('input', array('type' => 'submit',
'class' => 'button mainaction', 'value' => $this->gettext('save'))
)
)
)
)
);
}
/**
* save junk_report settings :
* $frequency : never, daily, weekly, monthly (default to DEFAULT_FREQUENCY)
* $maxlength : integer (default to DEFAULT_MAXLENGTH)
*/
function save()
{
$frequency = rcube_utils::get_input_value('_frequency',rcube_utils::INPUT_POST);
$maxlength = rcube_utils::get_input_value('_maxlength',rcube_utils::INPUT_POST);
$this->prefs["frequency"] = $frequency;
$this->prefs["maxlength"] = $maxlength;
$this->user->save_prefs($this->prefs);
}
/**
* authenticate from token
* mark message as not junk
* display HTML result
*/
function not_junk()
{
$this->rcmail->output->include_script('../../plugins/markasjunk2/markasjunk2.js');
$this->rcmail->output->include_script('../../plugins/junk_report/junk_report.js');
$this->require_plugin('markasjunk2');
$this->register_handler('plugin.body', array($this, 'not_junk_body'));
$this->rcmail->output->set_pagetitle($this->gettext('not_junk'));
$this->rcmail->output->send('plugin');
}
function not_junk_body()
{
// TODO authenticate
//return html::p(array('class' => ''), $this->gettext('auth_failed'));
// TODO mark as not junk
$uid = rcube_utils::get_input_value('_uid',rcube_utils::INPUT_GET);
// V1 : use rcmail : code is executed after load, but list does not work, markasjunk functions are prefixed with "rcmail."
//$this->rcmail->output->command('command', 'list', "Junk");
//$this->rcmail->output->set_env('uid', $uid);
//echo "<script>console.table($temp)</script>";
//$this->rcmail->output->command('rcmail_markasjunk2_notjunk', '');
//$this->rcmail->output->command('rcmail_markasjunk2_move','INBOX',$uid);
// V2 : use api does nothing
//$this->api->output->command('command', 'list', "Junk");
// V3 : use external js
//$this->rcmail->output->command('rcmail_junk_report_move', $uid);
// V4 : mix php and js
// This is only working after 3 repeats of clicking the restore link
// Also, this had to be done on the same page (not the one created) and you don't refresh the page
// Maybe it could be the cache?
$this->rcmail->output->set_env('uid', $uid);
$this->rcmail->output->command('rcmail_junk_report_move', $uid);
return html::p(array('class' => ''), $this->gettext('waiting'));
}
/**
* scan all $maildir/domain/mailbox/$junkdir
* check if $frequency matches current date
* generate a HTML/text report with the last $maxlength messages
* send an email to the mailbox
*/
function cron()
{
// TODO
}
}