diff options
author | Hugues Hiegel <hugues@hiegel.fr> | 2013-09-12 11:35:26 +0200 |
---|---|---|
committer | Hugues Hiegel <root@paranoid> | 2013-11-08 17:40:16 +0100 |
commit | 31de4bc5ebf9556817554ae9630ca06e92fd7218 (patch) | |
tree | f98afd42b6f4f818b3f4c489b2e6a7b3912dbb93 /plugins/markasjunk2/drivers/edit_headers.php | |
parent | ef14bd0d8d58ae0f57aa1969e31a5373aa441dba (diff) |
Updates / Plugins
Diffstat (limited to 'plugins/markasjunk2/drivers/edit_headers.php')
-rw-r--r-- | plugins/markasjunk2/drivers/edit_headers.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/plugins/markasjunk2/drivers/edit_headers.php b/plugins/markasjunk2/drivers/edit_headers.php new file mode 100644 index 000000000..9ee71ff79 --- /dev/null +++ b/plugins/markasjunk2/drivers/edit_headers.php @@ -0,0 +1,53 @@ +<?php + +/** + * Edit headers + * @version 1.0 + * @author Philip Weir + */ + +class markasjunk2_edit_headers +{ + public function spam(&$uids) + { + $this->_edit_headers($uids, true); + } + + public function ham(&$uids) + { + $this->_edit_headers($uids, false); + } + + private function _edit_headers(&$uids, $spam) + { + $rcmail = rcube::get_instance(); + $args = $spam ? $rcmail->config->get('markasjunk2_spam_patterns') : $rcmail->config->get('markasjunk2_ham_patterns'); + + if (sizeof($args['patterns']) == 0) + return; + + $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST); + + $new_uids = array(); + foreach (explode(",", $uids) as $uid) { + $raw_message = $rcmail->storage->get_raw_body($uid); + $raw_headers = $rcmail->storage->get_raw_headers($uid); + + $updated_headers = preg_replace($args['patterns'], $args['replacements'], $raw_headers); + $raw_message = str_replace($raw_headers, $updated_headers, $raw_message); + + $saved = $rcmail->storage->save_message($mbox, $raw_message); + + if ($saved !== false) { + $rcmail->output->command('rcmail_markasjunk2_move', null, $uid); + array_push($new_uids, $saved); + } + + } + + if (sizeof($new_uids) > 0) + $uids = implode(',', $new_uids); + } +} + +?>
\ No newline at end of file |