summaryrefslogtreecommitdiff
path: root/plugins/markasjunk2/drivers/sa_detach.php
blob: 947b4b8a772f2e945f76c62f00b06f11c7872485 (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
<?php

/**
 * SpamAssassin detach ham driver
 * @version 2.0
 * @author Philip Weir
 */

class markasjunk2_sa_detach
{
	public function spam($uids)
	{
		// do nothing
	}

	public function ham(&$uids)
	{
		$rcmail = rcube::get_instance();
		$storage = $rcmail->storage;
		$mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST);

		$new_uids = array();
		foreach (explode(",", $uids) as $uid) {
			$saved = false;
			$message = new rcube_message($uid);

			if (sizeof($message->attachments) > 0) {
				foreach ($message->attachments as $part) {
					if ($part->ctype_primary == 'message' && $part->ctype_secondary == 'rfc822') {
						$orig_message_raw = $storage->get_message_part($message->uid, $part->mime_id, $part);
						$saved = $storage->save_message($mbox, $orig_message_raw);

						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);
	}
}

?>