Commit 51be0bb5 authored by arildb's avatar arildb

[NEW] Mail-in admin options: "Allow routing" and "Leave email"

parent 1961e754
......@@ -2096,6 +2096,7 @@ installer/schema/20130611_mailin_add_html_tiki.sql -text
installer/schema/20130614_mailin_add_admin_tiki.sql -text
installer/schema/20130616_mailin_add_namespace_tiki.sql -text
installer/schema/20130623_create_mailin_user_struct_tiki.sql -text
installer/schema/20130624_mailin_add_attr_tiki.sql -text
installer/schema/999999991_decode_pages_sources_tiki.php -text
installer/schema/99999999_image_plugins_kill_tiki.php -text
installer/schema/index.php -text
......
......@@ -1249,6 +1249,7 @@ CREATE TABLE `tiki_mailin_accounts` (
`anonymous` char(1) NOT NULL default 'y',
`admin` char(1) NOT NULL default 'y',
`attachments` char(1) NOT NULL default 'n',
`routing` char(1) NOT NULL default 'y',
`article_topicId` int(4) default NULL,
`article_type` varchar(50) default NULL,
`discard_after` varchar(255) default NULL,
......@@ -1257,6 +1258,7 @@ CREATE TABLE `tiki_mailin_accounts` (
`categoryId` int(12) NULL,
`namespace` varchar(20) default NULL,
`respond_email` char(1) NOT NULL default 'y',
`leave_email` char(1) NOT NULL default 'n',
PRIMARY KEY (`accountId`)
) ENGINE=MyISAM AUTO_INCREMENT=1 ;
......
ALTER TABLE `tiki_mailin_accounts` add COLUMN `routing` char(1) NULL AFTER `attachments`;
ALTER TABLE `tiki_mailin_accounts` add COLUMN `leave_email` char(1) NULL AFTER `respond_email`;
\ No newline at end of file
......@@ -117,20 +117,20 @@ class MailinLib extends TikiLib
* @param 0 $categoryId
* @return bool
*/
function replace_mailin_account($accountId, $account, $pop, $port, $username, $clearpass, $smtp, $useAuth, $smtpPort, $type, $active, $anonymous, $admin, $attachments, $article_topicId = NULL, $article_type = NULL, $discard_after=NULL, $show_inlineImages='n', $save_html='y', $categoryId = 0, $namespace='', $respond_email = 'y')
function replace_mailin_account($accountId, $account, $pop, $port, $username, $clearpass, $smtp, $useAuth, $smtpPort, $type, $active, $anonymous, $admin, $attachments, $routing, $article_topicId = NULL, $article_type = NULL, $discard_after=NULL, $show_inlineImages='n', $save_html='y', $categoryId = 0, $namespace='', $respond_email = 'y', $leave_email = 'n')
{
// Encrypt password
$pass = $this->encryptPassword($clearpass);
if ($accountId) {
$bindvars = array($account,$pop,(int)$port,(int)$smtpPort,$username,$pass,$smtp,$useAuth,$type,$active,$anonymous,$admin,$attachments,(int)$article_topicId,$article_type,$discard_after,$show_inlineImages,$save_html,$categoryId, $namespace, $respond_email, (int)$accountId);
$query = "update `tiki_mailin_accounts` set `account`=?, `pop`=?, `port`=?, `smtpPort`=?, `username`=?, `pass`=?, `smtp`=?, `useAuth`=?, `type`=?, `active`=?, `anonymous`=?, `admin`=?, `attachments`=?, `article_topicId`=?, `article_type`=? , `discard_after`=?, `show_inlineImages`=?, `save_html`=?, `categoryId`=?, `namespace`=?, `respond_email`=? where `accountId`=?";
$bindvars = array($account,$pop,(int)$port,(int)$smtpPort,$username,$pass,$smtp,$useAuth,$type,$active,$anonymous,$admin,$attachments,$routing,(int)$article_topicId,$article_type,$discard_after,$show_inlineImages,$save_html,$categoryId, $namespace, $respond_email, $leave_email, (int)$accountId);
$query = "update `tiki_mailin_accounts` set `account`=?, `pop`=?, `port`=?, `smtpPort`=?, `username`=?, `pass`=?, `smtp`=?, `useAuth`=?, `type`=?, `active`=?, `anonymous`=?, `admin`=?, `attachments`=?, `routing`=?, `article_topicId`=?, `article_type`=? , `discard_after`=?, `show_inlineImages`=?, `save_html`=?, `categoryId`=?, `namespace`=?, `respond_email`=?, `leave_email`=? where `accountId`=?";
$result = $this->query($query, $bindvars);
} else {
$bindvars = array($account,$pop,(int)$port,(int)$smtpPort,$username,$pass,$smtp,$useAuth,$type,$active,$anonymous,$admin,$attachments,(int)$article_topicId,$article_type, $show_inlineImages, $save_html, $categoryId, $namespace, $respond_email);
$query = "delete from `tiki_mailin_accounts` where `account`=? and `pop`=? and `port`=? and `smtpPort`=? and `username`=? and `pass`=? and `smtp`=? and `useAuth`=? and `type`=? and `active`=? and `anonymous`=? and `admin`=? and `attachments`=? and `article_topicId`=?, `article_type`=?, `show_inlineImages`=?, `save_html`=?, `categoryId`=?, `namespace`=?, `respond_email`=?";
$bindvars = array($account,$pop,(int)$port,(int)$smtpPort,$username,$pass,$smtp,$useAuth,$type,$active,$anonymous,$admin,$attachments,$routing,(int)$article_topicId,$article_type, $show_inlineImages, $save_html, $categoryId, $namespace, $respond_email, $leave_email);
$query = "delete from `tiki_mailin_accounts` where `account`=? and `pop`=? and `port`=? and `smtpPort`=? and `username`=? and `pass`=? and `smtp`=? and `useAuth`=? and `type`=? and `active`=? and `anonymous`=? and `admin`=? and `attachments`=? and `routing`=? and `article_topicId`=?, `article_type`=?, `show_inlineImages`=?, `save_html`=?, `categoryId`=?, `namespace`=?, `respond_email`=?, `leave_email`=?";
$result = $this->query($query, $bindvars, -1, -1, false);
$query = "insert into `tiki_mailin_accounts`(`account`,`pop`,`port`,`smtpPort`,`username`,`pass`,`smtp`,`useAuth`,`type`,`active`,`anonymous`,`admin`,`attachments`,`article_topicId`,`article_type`,`show_inlineImages`, `save_html`, `categoryId`, `namespace`, `respond_email`) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$query = "insert into `tiki_mailin_accounts`(`account`,`pop`,`port`,`smtpPort`,`username`,`pass`,`smtp`,`useAuth`,`type`,`active`,`anonymous`,`admin`,`attachments`,`routing`,`article_topicId`,`article_type`,`show_inlineImages`, `save_html`, `categoryId`, `namespace`, `respond_email`, `leave_email`) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$result = $this->query($query, $bindvars);
}
return true;
......
......@@ -13,11 +13,13 @@
<th>{tr}Anonym{/tr}</th>
<th>{tr}Admin{/tr}</th>
<th>{tr}Attach{/tr}</th>
<th>{tr}Route{/tr}</th>
<th>{tr}Inline{/tr}</th>
<th>{tr}HTML{/tr}</th>
<th>{tr}Categ{/tr}</th>
<th>{tr}Namespace{/tr}</th>
<th>{tr}Email{/tr}</th>
<th>{tr}Leave{/tr}</th>
</tr>
{cycle values="even,odd" print=false}
{section name=ix loop=$accounts}
......@@ -32,11 +34,13 @@
<td class="text">{tr}{$accounts[ix].anonymous}{/tr}</td>
<td class="text">{tr}{$accounts[ix].admin}{/tr}</td>
<td class="text">{tr}{$accounts[ix].attachments}{/tr}</td>
<td class="text">{tr}{$accounts[ix].routing}{/tr}</td>
<td class="text">{tr}{$accounts[ix].show_inlineImages}{/tr}</td>
<td class="text">{tr}{$accounts[ix].save_html}{/tr}</td>
<td class="text">{tr}{$accounts[ix].categoryId}{/tr}</td>
<td class="text">{tr}{$accounts[ix].namespace}{/tr}</td>
<td class="text">{tr}{$accounts[ix].respond_email}{/tr}</td>
<td class="text">{tr}{$accounts[ix].leave_email}{/tr}</td>
</tr>
{/section}
......@@ -198,6 +202,20 @@
{/if}
</td>
</tr>
<tr>
<td>{tr}Allow Routing{/tr}</td>
<td colspan="3">
{if $prefs.feature_wiki eq 'y'}
{tr}Yes{/tr}
<input type="radio" name="routing" {if $info.routing eq 'y'}checked="checked"{/if} value="y">
{tr}No{/tr}
<input type="radio" name="routing" {if $info.routing eq 'n'}checked="checked"{/if} value="n">
{else}
<a href="tiki-admin.php?page=wiki&cookietab=1&highlight=feature_wiki">Activate wiki</a>
{/if}
</td>
<td>{tr}Allow per user routing of incoming email to structures{/tr}.</td>
</tr>
<tr>
<td>{tr}Show inline images{/tr}</td>
<td colspan="3">
......@@ -261,6 +279,18 @@
<input type="radio" name="respond_email" {if $info.respond_email eq 'n'}checked="checked"{/if} value="n">
</td>
</tr>
<tr>
<td>{tr}Leave email on server on error{/tr}</td>
<td colspan="3">
&nbsp;&nbsp;
{tr}Yes{/tr}
<input type="radio" name="leave_email" {if $info.leave_email eq 'y'}checked="checked"{/if} value="y">
&nbsp;&nbsp;
{tr}No{/tr}
<input type="radio" name="leave_email" {if $info.leave_email eq 'n'}checked="checked"{/if} value="n">
</td>
<td>{tr}Leave the email on the mail server, when an error occurs and the content has not been integrated into Tiki.{/tr}.</td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="4"><input type="submit" name="new_acc" value="{if $accountId eq 0}{tr}Add{/tr}{else}{tr}Save{/tr}{/if}"></td>
......
......@@ -61,6 +61,7 @@ if (isset($_REQUEST['new_acc'])) {
$_REQUEST['anonymous'],
$_REQUEST['admin'],
$_REQUEST['attachments'],
$_REQUEST['routing'],
$_REQUEST['article_topicId'],
$_REQUEST['article_type'],
$_REQUEST['discard_after'],
......@@ -68,7 +69,8 @@ if (isset($_REQUEST['new_acc'])) {
$_REQUEST['save_html'],
$_REQUEST['categoryId'],
$_REQUEST['namespace'],
$_REQUEST['respond_email']
$_REQUEST['respond_email'],
$_REQUEST['leave_email']
);
$tikifeedback[] = array(
......@@ -101,6 +103,7 @@ if ($_REQUEST['accountId']) {
$info['anonymous'] = 'n';
$info['admin'] = 'y';
$info['attachments'] = 'y';
$info['routing'] = 'y';
$info['article_topicId'] = '';
$info['article_type'] = '';
$info['show_inlineImages'] = 'y';
......@@ -108,6 +111,7 @@ if ($_REQUEST['accountId']) {
$info['categoryId'] = 0;
$info['namespace'] = '';
$info['respond_email'] = 'y';
$info['leave_email'] = 'n';
}
$smarty->assign('info', $info);
......
......@@ -337,6 +337,8 @@ foreach ($accs['data'] as $acc) {
$debugger->var_dump('$pop3');
}
} else {
$hasError = true;
$content.= "Messages:" . $mailsum . "<br />";
for ($i = 1; $i <= $mailsum; $i++) {
$aux = $pop3->getParsedHeaders($i);
......@@ -484,6 +486,7 @@ foreach ($accs['data'] as $acc) {
} else {
$content.= "Article: $title has been created<br />";
}
$hasError = false;
}
} else { //else if ($acc['type'] == 'article-put')
if ($acc['type'] == 'wiki') {
......@@ -541,9 +544,11 @@ foreach ($accs['data'] as $acc) {
$mail_data = $smarty->fetchLang($l, "mail/mailin_reply_subject.tpl");
$mail->setSubject($mail_data . $page);
}
$res = $mail->send(array($email_from), 'mail');
$content.= "Response sent<br />";
//end if ($acc['type'] == 'wiki-get' || ($acc['type'] == 'wiki' && $method == "GET"))
if ($processEmail) {
$res = $mail->send(array($email_from), 'mail');
$content.= "Response sent<br />";
$hasError = false;
}
} elseif ($acc['type'] == 'wiki-put' || ($acc['type'] == 'wiki' && $method == "PUT")) {
//////////////
......@@ -560,14 +565,15 @@ foreach ($accs['data'] as $acc) {
}
// Load user routing
$route = null;
$routes = $usermailinlib->locate_struct($chkUser, $aux['Subject'], $body);
if (!empty($routes['data'])) {
$content.= "User route from pattern: '".$routes['data'][0]['subj_pattern']."' / '".$routes['data'][0]['body_pattern']."'<br />";
$route = $routes['data'][0]; // Only use the first route
$route = array();
if ($acc['routing'] === 'y') {
$routes = $usermailinlib->locate_struct($chkUser, $aux['Subject'], $body);
if (!empty($routes['data'])) {
$content.= "User route from pattern: '".$routes['data'][0]['subj_pattern']."' / '".$routes['data'][0]['body_pattern']."'<br />";
$route = $routes['data'][0]; // Only use the first route
}
}
// Check permissions
if (($acc["anonymous"] == 'n') && (!$userlib->user_has_permission($chkUser, 'tiki_p_admin'))) {
if ($tikilib->page_exists($page)) {
......@@ -593,7 +599,7 @@ foreach ($accs['data'] as $acc) {
$can_addAttachment = 'n';
$show_inlineImages = 'n';
}
if (!empty($routes)) {
if (!empty($route)) {
if (!$userlib->object_has_permission($chkUser, $acc['categoryId'], 'category', 'tiki_p_edit_structures')) {
$content.= $chkUser." cannot edit structures: ".$page."<br />";
$processEmail = false;
......@@ -608,7 +614,7 @@ foreach ($accs['data'] as $acc) {
$can_addAttachment = 'n';
$show_inlineImages = 'n';
}
if (!empty($routes)) {
if (!empty($route)) {
if (!$userlib->user_has_permission($chkUser, 'tiki_p_edit_structures')) {
$content.= $chkUser." cannot edit structures: ".$page."<br />";
$processEmail = false;
......@@ -687,6 +693,7 @@ foreach ($accs['data'] as $acc) {
$parsed_data['wysiwyg'] //wysiwyg
);
$content.= "Page: $page has been updated<br />";
$hasError = false;
} else {
// Create a regular page
......@@ -699,6 +706,7 @@ foreach ($accs['data'] as $acc) {
$parsed_data['wysiwyg'] //wysiwyg
);
$content.= "Page: $page has been created<br />";
$hasError = false;
// Assign category, if specified
if ($prefs['feature_categories'] && isset($acc['categoryId'])) {
......@@ -734,6 +742,7 @@ foreach ($accs['data'] as $acc) {
$parsed_data['wysiwyg'] //wysiwyg
);
$content.= "Page: $page has been updated<br />";
$hasError = false;
}
}
}
......@@ -782,6 +791,7 @@ foreach ($accs['data'] as $acc) {
$parsed_data['wysiwyg'] //wysiwyg
);
$content.= "Page: $page has been created<br />";
$hasError = false;
} else {
$info = $tikilib->get_page_info($page);
if ($acc['type'] == 'wiki-append' || $acc['type'] == 'wiki' && $method == "APPEND") {
......@@ -801,6 +811,7 @@ foreach ($accs['data'] as $acc) {
$parsed_data['wysiwyg'] //wysiwyg
);
$content.= "Page: $page has been updated<br />";
$hasError = false;
}
}
}
......@@ -827,8 +838,10 @@ foreach ($accs['data'] as $acc) {
}
}
// Remove the email from the pop3 server
$pop3->deleteMsg($i);
$content.= "Deleted message<br />";
if (!$hasError || ($hasError && ($acc['leave_email'] !== 'y'))) {
$pop3->deleteMsg($i);
$content.= "Deleted message<br />";
}
}
}
......
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