tiki-mailin-code.php 1.98 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2013 by authors of the Tiki Wiki CMS Groupware Project
changi67's avatar
changi67 committed
6
//
7 8
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
changi67's avatar
changi67 committed
9 10
// $Id$

11 12
use Tiki\MailIn;

changi67's avatar
changi67 committed
13 14
require_once ('tiki-setup.php');
$access->check_script($_SERVER["SCRIPT_NAME"], basename(__FILE__));
15
include_once ('lib/mailin/mailinlib.php');
16 17
include_once ("lib/mail/mimelib.php");
include_once ("lib/webmail/tikimaillib.php");
18
include_once ('lib/wiki/wikilib.php');
19

20
$mailinlib = TikiLib::lib('mailin');
21

22 23
// Get a list of ACTIVE emails accounts configured for mailin procedures
$accs = $mailinlib->list_active_mailin_accounts(0, -1, 'account_desc', '');
24

25
// foreach account
26
foreach ($accs['data'] as $acc) {
27 28 29
	if (empty($acc['account'])) {
		continue;
	}
changi67's avatar
changi67 committed
30

31 32 33 34
	$account = MailIn\Account::fromDb($acc);
	$messages = $account->getMessages();

	foreach ($messages as $message) {
35
		$success = false;
36 37 38

		if (! $account->canReceive($message)) {
			$account->sendFailureResponse($message);
39 40 41 42 43 44
		} elseif ($action = $account->getAction($message)) {
			if (! $action->isEnabled()) {
				// Action configured, but not enabled
			} elseif ($account->isAnyoneAllowed() || $action->isAllowed($account, $message)) {
				$account->prepareMessage($message);
				$success = $action->execute($account, $message);
45
			} else {
46
				// TODO : Send permission denied message
47
			}
48
		} else {
49
			// Send failure response for no suitable action found
50
			$l = $prefs['language'];
51 52
			$subject = $smarty->fetchLang($l, "mail/mailin_help_subject.tpl");
			$smarty->assign('subject', $message->getSubject());
53
			$mail_data = $smarty->fetchLang($l, "mail/mailin_help.tpl");
54 55 56

			$mail = $account->getReplyMail($message);
			$mail->setSubject($subject);
57
			$mail->setText($mail_data);
58
			$account->sendFailureReply($message, $mail);
59
		}
changi67's avatar
changi67 committed
60

61 62 63 64
		if ($success) {
			$account->completeSuccess($message);
		} else {
			$account->completeFailure($message);
65 66
		}
	}
67
}