Commit 8487d68b authored by Benjamin Sonntag's avatar Benjamin Sonntag
Browse files

delete / undelete of emails now working. need cron for pop deletion

parent a022ae4a
......@@ -258,6 +258,7 @@ bureau/admin/mail_localbox_edit.inc.php -text
bureau/admin/mail_properties.php -text
bureau/admin/mail_redirection_doedit.php -text
bureau/admin/mail_redirection_edit.inc.php -text
bureau/admin/mail_undelete.php -text
bureau/admin/main.php -text
bureau/admin/mem_admin.php -text
bureau/admin/mem_chgmail.php -text
......
......@@ -27,7 +27,7 @@ require_once("../class/config.php");
$fields = array (
"d" => array ("request", "array", ""),
"domain" => array ("request", "string", ""),
"domain_id" => array ("request", "integer", ""),
"confirm" => array("request", "string", "n"),
);
getFields($fields);
......@@ -41,16 +41,19 @@ reset($d);
include_once ("head.php");
if ($confirm=="y") {
while (list($key,$val)=each($d)) {
if (!$mail->del_mail($val)) {
$error.=sprintf(_("The email address <b>%s</b> does not exist!")."<br />",$val);
} else {
$error.=sprintf(_("The email address <b>%s</b> has been deleted!")."<br />",$val);
}
}
include("mail_list.php");
exit();
$error="";
while (list($key,$val)=each($d)) {
$mail->delete($val);
$error.=$err->errstr()."<br />";
/*
$error.=$err->errstr()."<br />"; //sprintf(_("The email address <b>%s</b> does not exist!")."<br />",$val);
} else {
$error.=sprintf(_("The email address <b>%s</b> has been deleted!")."<br />",$val);
}
*/
}
include("mail_list.php");
exit();
}
?>
......@@ -63,13 +66,14 @@ include("mail_list.php");
<form method="post" action="mail_del.php" id="main">
<p>
<input type="hidden" name="confirm" value="y" />
<input type="hidden" name="domain" value="<?php echo $domain; ?>" />
<input type="hidden" name="domain_id" value="<?php echo $domain_id; ?>" />
<?php
while (list($key,$val)=each($d)) {
$m=$mail->get_details($val);
echo "<input type=\"hidden\" name=\"d[]\" value=\"$val\" />";
echo $val."<br />";
echo $m["address"]."@".$m["domain"]."<br />";
}
?>
......
......@@ -95,6 +95,7 @@ if (empty($mails_list)){ // If there is no mail for this domain
</fieldset>
<form method="post" action="mail_del.php">
<input type="hidden" name="domain_id" value="<?php echo $domain_id; ?>" />
<table class="tlist">
<tr><th></th><th></th><th><?php __("Enabled");?></th><th style="text-align:right"><?php __("Address"); ?></th><th><?php __("Pop/Imap"); ?></th><th><?php __("Other recipients"); ?></th><th><?php __("Last login time"); ?></th></tr>
<?php
......@@ -102,16 +103,22 @@ if (empty($mails_list)){ // If there is no mail for this domain
$col=1; $i=0;
//listing of every mail of the current domain.
while (list($key,$val)=each($mails_list)){
$col=3-$col;
$col=3-$col; $grey="";
?>
<tr class="lst<?php echo $col; ?>">
<?php if (!$val["type"]) { ?>
<td align="center">
<input class="inc" type="checkbox" id="del_<?php echo $i; ?>" name="d[]\" value="<?php ehe($val["address"]."@".$val["domain"]); ?>" />
<?php if ($val["mail_action"]=="DELETING") { $grey="grey"; ?>
<td colspan="3"><?php __("Deleting..."); ?></td>
<?php } else if ($val["mail_action"]=="DELETE") { $grey="grey"; ?>
<td></td>
<td><div class="ina"><a href="mail_undelete.php?search=<?php ehe($search); ?>&offset=<?php ehe($offset); ?>&count=<?php ehe($count); ?>&domain_id=<?php ehe($domain_id); ?>&mail_id=<?php echo $val["id"] ?>"><img src="images/undelete.png" alt="<?php __("Undelete"); ?>" /><?php __("Undelete"); ?></a></div></td>
<td><img src="images/check_no.png" alt="<?php __("Disabled"); ?>" /></td>
<?php } else if (!$val["type"]) { ?>
<td align="center">
<input class="inc" type="checkbox" id="del_<?php echo $i; ?>" name="d[]" value="<?php ehe($val["id"]); ?>" />
</td>
<td>
<td class="<?php echo $grey; ?>">
<div class="ina"><a href="mail_properties.php?mail_id=<?php echo $val["id"] ?>"><img src="images/edit.png" alt="<?php __("Edit"); ?>" /><?php __("Edit"); ?></a></div></td>
<td><?php if ($val["enabled"] ) { ?>
<td class="<?php echo $grey; ?>"><?php if ($val["enabled"] ) { ?>
<img src="images/check_ok.png" alt="<?php __("Enabled"); ?>" />
<?php } else { ?>
<img src="images/check_no.png" alt="<?php __("Disabled"); ?>" />
......@@ -120,14 +127,14 @@ while (list($key,$val)=each($mails_list)){
<?php } else { ?>
<td colspan="3"></td>
<?php } ?>
<td style="text-align:right"><?php echo $val["address"]."@".$domain ?></td>
<td class="<?php echo $grey; ?>" style="text-align:right"><?php echo $val["address"]."@".$domain ?></td>
<?php if ($val["type"]) { ?>
<td colspan="2"><?php echo $val["typedata"]; ?></td>
<?php } else { ?>
<td><?php if ($val["islocal"]) echo format_size($val["used"])."/".format_size($val["quota"]); else __("No"); ?></td>
<td><?php echo $val["recipients"]; /* TODO : if >60chars, use "..." + js close/open */ ?></td>
<td class="<?php echo $grey; ?>"><?php if ($val["islocal"]) echo format_size($val["used"])."/".format_size($val["quota"]); else __("No"); ?></td>
<td class="<?php echo $grey; ?>"><?php echo $val["recipients"]; /* TODO : if >60chars, use "..." + js close/open */ ?></td>
<?php } ?>
<td><?php if ($val["islocal"]) {
<td class="<?php echo $grey; ?>"><?php if ($val["islocal"]) {
if (date("Y-m-d")==substr($val["lastlogin"],0,10)) echo substr($val["lastlogin"],11,5); else if (substr($val["lastlogin"],0,10)=="0000-00-00") __("Never"); else echo format_date(_('%3$d-%2$d-%1$d'),$val["lastlogin"]);
} ?></td>
</tr>
......
<?php
/*
----------------------------------------------------------------------
AlternC - Web Hosting System
Copyright (C) 2000-2012 by the AlternC Development Team.
https://alternc.org/
----------------------------------------------------------------------
LICENSE
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License (GPL)
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
To read the license please visit http://www.gnu.org/copyleft/gpl.html
----------------------------------------------------------------------
Purpose of file: undelete one mailbox
----------------------------------------------------------------------
*/
require_once("../class/config.php");
$fields = array (
"mail_id" => array ("request", "integer", ""),
);
getFields($fields);
$mail->undelete($mail_id);
$error=$err->errstr();
include("mail_list.php");
......@@ -461,3 +461,6 @@ input#dir, input#sub_local {
padding-top: 6px;
}
.grey {
color: #999;
}
\ No newline at end of file
......@@ -1181,6 +1181,32 @@ class m_dom {
return false;
}
}
/* ----------------------------------------------------------------- */
/**
* Returns the id of a domain for the current user, from it's domain name
* @param $domain string the domain name to search for
* @return integer the domain id, or false with an error raised.
*/
function get_domain_byname($domain) {
global $db,$err,$cuid;
$domain=trim($domain);
$db->query("SELECT id FROM domaines WHERE domaine='".addslashes($domain)."' AND compte=$cuid;");
if ($db->next_record()) {
$id=$db->f("id");
if (!$id) {
$err->raise("dom",_("This domain is not installed in your account"));
return false;
} else {
return $id;
}
} else {
$err->raise("dom",_("This domain is not installed in your account"));
return false;
}
}
/* ----------------------------------------------------------------- */
......
......@@ -118,7 +118,7 @@ class m_mail {
$db->next_record();
$this->total=$db->f("total");
$db->query("SELECT a.id, a.address, a.password, a.enabled, d.domaine AS domain, m.quota*1024*1024 AS quota, m.bytes AS used, NOT ISNULL(m.id) AS islocal, a.type, r.recipients, m.lastlogin
$db->query("SELECT a.id, a.address, a.password, a.`enabled`, a.mail_action, d.domaine AS domain, m.quota*1024*1024 AS quota, m.bytes AS used, NOT ISNULL(m.id) AS islocal, a.type, r.recipients, m.lastlogin
FROM (address a LEFT JOIN mailbox m ON m.address_id=a.id) LEFT JOIN recipient r ON r.address_id=a.id, domaines d
WHERE $where AND d.id=a.domain_id
LIMIT $offset,$count;");
......@@ -142,7 +142,7 @@ class m_mail {
/* ----------------------------------------------------------------- */
/** Function used to insert a new mail into de the db
/** Function used to insert a new mail into the db
* should be used by the web interface, not by third-party programs.
*
* This function calls the hook "hooks_mail_cancreate"
......@@ -155,7 +155,7 @@ class m_mail {
* or false if an error occured ($err is filled accordingly)
*/
function create($dom_id, $mail){
global $err,$db,$cuid,$quota,$dom;
global $err,$db,$cuid,$quota,$dom,$hooks;
$err->log("mail","create");
// Validate the domain id
......@@ -203,13 +203,13 @@ class m_mail {
* @return array a hashtable with all the informations for that email
*/
function get_details($mail_id) {
global $db, $err, $cuid;
global $db, $err, $cuid, $hooks;
$err->log("mail","get_details");
$mail_id=intval($mail_id);
// We fetch all the informations for that email: these will fill the hastable :
$db->query("SELECT a.address, a.password, a.enabled, d.domaine AS domain, m.quota, m.bytes/1024/1024 AS used, NOT ISNULL(m.id) AS islocal, a.type
$db->query("SELECT a.address, a.password, a.`enabled`, d.domaine AS domain, m.quota, m.bytes/1024/1024 AS used, NOT ISNULL(m.id) AS islocal, a.type
FROM address a LEFT JOIN mailbox m ON m.address_id=a.id, domaines d WHERE a.id=$mail_id AND d.id=a.domain_id;");
if (! $db->next_record()) return false;
$details=$db->Record;
......@@ -222,7 +222,131 @@ class m_mail {
}
/* ----------------------------------------------------------------- */
/** Check if an email is mine ...
*
* @param $mail_id integer the number of the email to check
* @return string the complete email address if that's mine, false if not
* ($err is filled accordingly)
*/
function is_it_my_mail($mail_id){
global $err,$db,$cuid;
$mail_id=intval($mail_id);
$db->query("SELECT concat(a.address,'@',d.domaine) AS email FROM address a, domaines d WHERE d.id=a.domain_id AND a.id=$mail_id AND d.compte=$cuid;");
if ($db->next_record()) {
return $db->f("email");
} else {
$err->raise("mail",_("This email is not yours, you can't change anything on it"));
return false;
}
}
/* ----------------------------------------------------------------- */
/** Function used to delete a mail from the db
* should be used by the web interface, not by third-party programs.
*
* @param $mail_id integer the number of the email to delete
* @return true if the email has been properly deleted
* or false if an error occured ($err is filled accordingly)
*/
function delete($mail_id){
global $err,$db,$cuid,$quota,$dom,$hooks;
$err->log("mail","delete");
$mail_id=intval($mail_id);
if (!$mail_id) {
$err->raise("mail",_("The email you entered is syntaxically incorrect"));
return false;
}
// Validate that this email is owned by me...
if (!($mail=$this->is_it_my_mail($mail_id))) {
return false;
}
// Search for that address:
$db->query("SELECT a.id, a.type, a.mail_action, m.mail_action AS mailbox_action, NOT ISNULL(m.id) AS islocal FROM address a LEFT JOIN mailbox m ON m.address_id=a.id WHERE a.id='$mail_id';");
if (!$db->next_record()) {
$err->raise("mail",_("The email %s does not exist, it can't be deleted"),$mail);
return false;
}
if ($db->f("type")!="") { // Technically special : mailman, sympa ...
$err->raise("mail",_("The email %s is special, it can't be deleted"),$mail);
return false;
}
if ($db->f("mailbox_action")!="" || $db->f("mail_action")!="") { // will be deleted soon ...
$err->raise("mail",_("The email %s is already marked for deletion, it can't be deleted"),$mail);
return false;
}
$mail_id=$db->f("id");
if ($db->f("islocal")) {
// If it's a pop/imap mailbox, mark it for deletion
$db->query("UPDATE address SET mail_action='DELETE', enabled=0 WHERE id='$mail_id';");
$db->query("UPDATE mailbox SET mail_action='DELETE' WHERE address_id='$mail_id';");
$err->raise("mail",_("The email %s has been marked for deletion"),$mail);
} else {
// If it's only aliases, delete it NOW.
$db->query("DELETE FROM address WHERE id='$mail_id';");
$db->query("DELETE FROM mailbox WHERE address_id='$mail_id';");
$db->query("DELETE FROM recipient WHERE address_id='$mail_id';");
$err->raise("mail",_("The email %s has been successfully deleted"),$mail);
}
return true;
}
/* ----------------------------------------------------------------- */
/** Function used to undelete a pending deletion mail from the db
* should be used by the web interface, not by third-party programs.
*
* @param $mail_id integer the email id
* @return true if the email has been properly undeleted
* or false if an error occured ($err is filled accordingly)
*/
function undelete($mail_id){
global $err,$db,$cuid,$quota,$dom,$hooks;
$err->log("mail","undelete");
$mail_id=intval($mail_id);
if (!$mail_id) {
$err->raise("mail",_("The email you entered is syntaxically incorrect"));
return false;
}
// Validate that this email is owned by me...
if (!($mail=$this->is_it_my_mail($mail_id))) {
return false;
}
// Search for that address:
$db->query("SELECT a.id, a.type, a.mail_action, m.mail_action AS mailbox_action, NOT ISNULL(m.id) AS islocal FROM address a LEFT JOIN mailbox m ON m.address_id=a.id WHERE a.id='$mail_id';");
if (!$db->next_record()) {
$err->raise("mail",_("The email %s does not exist, it can't be undeleted"),$mail);
return false;
}
if ($db->f("type")!="") { // Technically special : mailman, sympa ...
$err->raise("mail",_("The email %s is special, it can't be undeleted"),$mail);
return false;
}
if ($db->f("mailbox_action")!="DELETE" || $db->f("mail_action")!="DELETE") { // will be deleted soon ...
$err->raise("mail",_("Sorry, deletion of email %s is already in progress, or not marked for deletion, it can't be undeleted"),$mail);
return false;
}
$mail_id=$db->f("id");
if ($db->f("islocal")) {
// If it's a pop/imap mailbox, mark it for deletion
$db->query("UPDATE address SET mail_action='', `enabled`=1 WHERE id='$mail_id';");
$db->query("UPDATE mailbox SET mail_action='' WHERE address_id='$mail_id';");
$err->raise("mail",_("The email %s has been undeleted"),$mail);
return true;
} else {
$err->raise("mail",_("-- Program Error -- The email %s can't be undeleted"),$mail);
return false;
}
}
......@@ -322,7 +446,7 @@ class m_mail {
function enable($mail_id){
global $db,$err;
$err->log("mail","enable");
if( !$db->query("UPDATE address SET enabled=1 where id=$mail_id;"))return false;
if( !$db->query("UPDATE address SET `enabled`=1 where id=$mail_id;"))return false;
}
......@@ -333,7 +457,7 @@ class m_mail {
function disable($mail_id){
global $db,$err;
$err->log("mail","enable");
if( !$db->query("UPDATE address SET enabled=0 where id=$mail_id;")) return false;
if( !$db->query("UPDATE address SET `enabled`=0 where id=$mail_id;")) return false;
}
......
......@@ -6,8 +6,8 @@
msgid ""
msgstr ""
"Project-Id-Version: AlternC-awstats module 2.0\n"
"Report-Msgid-Bugs-To: benjamin@alternc.org\n"
"POT-Creation-Date: 2007-08-22 17:38+0200\n"
"Report-Msgid-Bugs-To: alternc@packages.debian.org\n"
"POT-Creation-Date: 2012-08-21 12:36+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......
......@@ -14,8 +14,8 @@
msgid ""
msgstr ""
"Project-Id-Version: 0.3.1\n"
"Report-Msgid-Bugs-To: benjamin@alternc.org\n"
"POT-Creation-Date: 2007-08-22 17:38+0200\n"
"Report-Msgid-Bugs-To: alternc@packages.debian.org\n"
"POT-Creation-Date: 2012-08-21 12:36+0200\n"
"PO-Revision-Date: 2005-05-15 18:24+0200\n"
"Last-Translator: Benjamin Sonntag <benjamin@altercn.org>\n"
"Language-Team: french <dev@alternc.org>\n"
......
Supports Markdown
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