Commit 819f258b authored by lphuberdeau's avatar lphuberdeau

[MOD] Adding command line utility for mail-in, fixing notices

parent 705e9e55
......@@ -2959,6 +2959,7 @@ lib/core/Tiki/Command/IndexCatchUpCommand.php -text
lib/core/Tiki/Command/IndexOptimizeCommand.php -text
lib/core/Tiki/Command/IndexRebuildCommand.php -text
lib/core/Tiki/Command/InstallCommand.php -text
lib/core/Tiki/Command/MailInPollCommand.php -text
lib/core/Tiki/Command/NotificationDigestCommand.php -text
lib/core/Tiki/Command/ProfileBaselineCommand.php -text
lib/core/Tiki/Command/ProfileExport/ActivityRuleSet.php -text
......
......@@ -86,6 +86,7 @@ if ($isInstalled && ! $installer->requiresUpdate()) {
$console->add(new Tiki\Command\IndexRebuildCommand);
$console->add(new Tiki\Command\IndexOptimizeCommand);
$console->add(new Tiki\Command\IndexCatchUpCommand);
$console->add(new Tiki\Command\MailInPollCommand);
$console->add(new Tiki\Command\NotificationDigestCommand);
$console->add(new Tiki\Command\ProfileForgetCommand);
$console->add(new Tiki\Command\ProfileInstallCommand);
......@@ -95,6 +96,7 @@ if ($isInstalled && ! $installer->requiresUpdate()) {
$console->add(new Tiki\Command\UnavailableCommand('index:rebuild'));
$console->add(new Tiki\Command\UnavailableCommand('index:optimize'));
$console->add(new Tiki\Command\UnavailableCommand('index:catch-up'));
$console->add(new Tiki\Command\UnavailableCommand('mail-in:poll'));
$console->add(new Tiki\Command\UnavailableCommand('notification:digest'));
$console->add(new Tiki\Command\UnavailableCommand('profile:forget'));
$console->add(new Tiki\Command\UnavailableCommand('profile:apply'));
......
<?php
// (c) Copyright 2002-2013 by authors of the Tiki Wiki CMS Groupware Project
//
// 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.
// $Id$
namespace Tiki\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
error_reporting(E_ALL);
use Tiki\MailIn;
use TikiLib;
class MailInPollCommand extends Command
{
protected function configure()
{
$this
->setName('mail-in:poll')
->setDescription('Read the mail-in messages');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$mailinlib = TikiLib::lib('mailin');
$accs = $mailinlib->list_active_mailin_accounts(0, -1, 'account_desc', '');
// foreach account
foreach ($accs['data'] as $acc) {
if (empty($acc['account'])) {
continue;
}
$account = MailIn\Account::fromDb($acc);
$account->check();
}
}
}
......@@ -82,17 +82,12 @@ class Account
{
}
function getMessages()
{
return $this->source->getMessages();
}
function completeSuccess($message)
private function completeSuccess($message)
{
$message->delete();
}
function completeFailure($message)
private function completeFailure($message)
{
if ($this->deleteOnError) {
$message->delete();
......@@ -101,10 +96,10 @@ class Account
function isAnyoneAllowed()
{
return $this->anonymous;
return $this->anonymousAllowed;
}
function canReceive(Source\Message $message)
private function canReceive(Source\Message $message)
{
$user = $message->getAssociatedUser();
$perms = TikiLib::lib('tiki')->get_user_permission_accessor($user, null, null);
......@@ -119,12 +114,12 @@ class Account
}
}
function getAction(Source\Message $message)
private function getAction(Source\Message $message)
{
return $this->actionFactory->createAction($this, $message);
}
function prepareMessage(Source\Message $message)
private function prepareMessage(Source\Message $message)
{
// TODO : This is rather primitive and implies we control the message source, need to make smarter
......@@ -233,5 +228,45 @@ class Account
{
return $this->inline_attachments;
}
function check()
{
$messages = $this->source->getMessages();
foreach ($messages as $message) {
$success = false;
if (! $this->canReceive($message)) {
$this->sendFailureResponse($message);
} elseif ($action = $this->getAction($message)) {
if (! $action->isEnabled()) {
// Action configured, but not enabled
} elseif ($this->isAnyoneAllowed() || $action->isAllowed($this, $message)) {
$this->prepareMessage($message);
$success = $action->execute($this, $message);
} else {
// TODO : Send permission denied message
}
} else {
// Send failure response for no suitable action found
$l = $prefs['language'];
$subject = $smarty->fetchLang($l, "mail/mailin_help_subject.tpl");
$smarty->assign('subject', $message->getSubject());
$mail_data = $smarty->fetchLang($l, "mail/mailin_help.tpl");
$mail = $this->getReplyMail($message);
$mail->setSubject($subject);
$mail->setText($mail_data);
$this->sendFailureReply($message, $mail);
}
if ($success) {
$this->completeSuccess($message);
} else {
$this->completeFailure($message);
}
}
}
}
......@@ -24,7 +24,7 @@ class SubjectPrefixFactory implements FactoryInterface
$subject = $message->getSubject();
foreach ($this->config as $prefix => $factory) {
if (strpos($subject, $prefix) === 0 || empty($prefix)) {
if (empty($prefix) || strpos($subject, $prefix) === 0) {
$subject = trim(substr($subject, strlen($prefix)));
$message->setSubject($subject);
......
......@@ -32,7 +32,7 @@ class Pop3 implements SourceInterface
$toDelete[] = $i;
});
$from = $source->from ?: $source->{'return-path'};
$message->setMessageId(preg_replace(['<', ']'], '', $source->{'message-id'}));
$message->setMessageId(str_replace(['<', ']'], '', $source->{'message-id'}));
$message->setRawFrom($from);
$message->setSubject($source->subject);
$message->setHtmlBody($this->getBody($source, 'text/html'));
......
......@@ -3635,7 +3635,7 @@ class TikiLib extends TikiDb_Bridge
{
global $user;
if ($type && $object) {
$context = array( 'type' => $objtype, 'object' => $object );
$context = array( 'type' => $type, 'object' => $object );
$accessor = Perms::get($context);
} else {
$accessor = Perms::get();
......
......@@ -12,10 +12,7 @@ use Tiki\MailIn;
require_once ('tiki-setup.php');
$access->check_script($_SERVER["SCRIPT_NAME"], basename(__FILE__));
include_once ('lib/mailin/mailinlib.php');
include_once ("lib/mail/mimelib.php");
include_once ("lib/webmail/tikimaillib.php");
include_once ('lib/wiki/wikilib.php');
$mailinlib = TikiLib::lib('mailin');
......@@ -29,39 +26,5 @@ foreach ($accs['data'] as $acc) {
}
$account = MailIn\Account::fromDb($acc);
$messages = $account->getMessages();
foreach ($messages as $message) {
$success = false;
if (! $account->canReceive($message)) {
$account->sendFailureResponse($message);
} 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);
} else {
// TODO : Send permission denied message
}
} else {
// Send failure response for no suitable action found
$l = $prefs['language'];
$subject = $smarty->fetchLang($l, "mail/mailin_help_subject.tpl");
$smarty->assign('subject', $message->getSubject());
$mail_data = $smarty->fetchLang($l, "mail/mailin_help.tpl");
$mail = $account->getReplyMail($message);
$mail->setSubject($subject);
$mail->setText($mail_data);
$account->sendFailureReply($message, $mail);
}
if ($success) {
$account->completeSuccess($message);
} else {
$account->completeFailure($message);
}
}
$account->check();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment