2008-09-09 17:48:07 +02:00
|
|
|
<?php
|
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (C) 2007 Easter-eggs
|
|
|
|
* http://ldapsaisie.labs.libre-entreprise.org
|
|
|
|
*
|
|
|
|
* Author: See AUTHORS file in top-level directory.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
2009-01-12 11:57:27 +01:00
|
|
|
// Messages d'erreur
|
2008-09-09 17:48:07 +02:00
|
|
|
|
2009-01-12 11:57:27 +01:00
|
|
|
// Support
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('MAILDIR_SUPPORT_01',
|
2009-03-13 22:32:08 +01:00
|
|
|
_("MAILDIR Support : Unable to load LSaddon::FTP.")
|
2009-01-12 11:57:27 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('MAILDIR_SUPPORT_02',
|
2009-02-14 00:06:58 +01:00
|
|
|
_("MAILDIR Support : The constant %{const} is not defined.")
|
2009-01-12 11:57:27 +01:00
|
|
|
);
|
2008-09-09 17:48:07 +02:00
|
|
|
|
2009-01-12 11:57:27 +01:00
|
|
|
// Autres erreurs
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('MAILDIR_01',
|
2009-02-14 00:06:58 +01:00
|
|
|
_("MAILDIR : Error while creating maildir on the remote server.")
|
2009-01-12 11:57:27 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('MAILDIR_02',
|
2009-02-14 00:06:58 +01:00
|
|
|
_("MAILDIR : Error while deleting the maildir on the remote server.")
|
2009-01-21 18:08:09 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('MAILDIR_03',
|
2009-02-14 00:06:58 +01:00
|
|
|
_("MAILDIR : Error while renaming the maildir on the remote server.")
|
2009-01-22 16:26:21 +01:00
|
|
|
);
|
2009-01-25 15:37:03 +01:00
|
|
|
LSerror :: defineError('MAILDIR_04',
|
2009-02-14 00:06:58 +01:00
|
|
|
_("MAILDIR : Error while recovering remote path of the maildir.")
|
2009-01-12 11:57:27 +01:00
|
|
|
);
|
2008-09-09 17:48:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Verification du support Maildir par ldapSaisie
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @retval boolean true si Maildir est pleinement supporté, false sinon
|
|
|
|
*/
|
|
|
|
function LSaddon_maildir_support() {
|
|
|
|
$retval=true;
|
|
|
|
|
|
|
|
// Dependance de librairie
|
|
|
|
if (!function_exists('createDirsByFTP')) {
|
2009-01-24 18:45:14 +01:00
|
|
|
if(!LSsession :: loadLSaddon('ftp')) {
|
|
|
|
LSerror :: addErrorCode('MAILDIR_SUPPORT_01');
|
2008-09-09 17:48:07 +02:00
|
|
|
$retval=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$MUST_DEFINE_CONST= array(
|
|
|
|
'LS_MAILDIR_FTP_HOST',
|
|
|
|
'LS_MAILDIR_FTP_USER',
|
2009-01-22 16:37:57 +01:00
|
|
|
'LS_MAILDIR_FTP_MAILDIR_PATH',
|
|
|
|
'LS_MAILDIR_FTP_MAILDIR_PATH_REGEX'
|
2008-09-09 17:48:07 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach($MUST_DEFINE_CONST as $const) {
|
2009-01-12 11:57:27 +01:00
|
|
|
if ( (!defined($const)) || (constant($const) == "")) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('MAILDIR_SUPPORT_02',$const);
|
2008-09-09 17:48:07 +02:00
|
|
|
$retval=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creation d'une Maildir via FTP
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject L'objet ldap
|
2009-01-21 18:08:09 +01:00
|
|
|
* @param[in] $dir Le chemin de la maildir. Si défini, la valeur ne sera pas
|
|
|
|
* récupérée dans le ldapObject
|
2008-09-09 17:48:07 +02:00
|
|
|
*
|
|
|
|
* @retval string True ou false si il y a un problème durant la création de la Maildir
|
|
|
|
*/
|
2009-01-21 18:08:09 +01:00
|
|
|
function createMaildirByFTP($ldapObject,$dir=null) {
|
|
|
|
if (!$dir) {
|
2009-01-22 16:26:21 +01:00
|
|
|
$dir = getMaildirPath($ldapObject);
|
|
|
|
if (!$dir) {
|
|
|
|
return;
|
|
|
|
}
|
2009-01-21 18:08:09 +01:00
|
|
|
}
|
2008-09-09 17:48:07 +02:00
|
|
|
$dirs = array(
|
|
|
|
$dir.'/cur',
|
|
|
|
$dir.'/new',
|
|
|
|
$dir.'/tmp'
|
|
|
|
);
|
2009-01-12 11:57:27 +01:00
|
|
|
if (!createDirsByFTP(LS_MAILDIR_FTP_HOST,LS_MAILDIR_FTP_PORT,LS_MAILDIR_FTP_USER,LS_MAILDIR_FTP_PWD,$dirs,LS_MAILDIR_FTP_MAILDIR_CHMOD)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('MAILDIR_01');
|
2008-09-09 17:48:07 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Suppression d'une Maildir via FTP
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject L'objet ldap
|
2009-01-21 18:08:09 +01:00
|
|
|
* @param[in] $dir Le chemin de la maildir. Si défini, la valeur ne sera pas
|
|
|
|
* récupérée dans le ldapObject
|
2008-09-09 17:48:07 +02:00
|
|
|
*
|
|
|
|
* @retval string True ou false si il y a un problème durant la suppression de la Maildir
|
|
|
|
*/
|
2009-01-21 18:08:09 +01:00
|
|
|
function removeMaildirByFTP($ldapObject,$dir=null) {
|
|
|
|
if (!$dir) {
|
2009-01-22 16:26:21 +01:00
|
|
|
$dir = getMaildirPath($ldapObject);
|
|
|
|
if (!$dir) {
|
|
|
|
return;
|
|
|
|
}
|
2009-01-21 18:08:09 +01:00
|
|
|
}
|
2008-09-09 17:48:07 +02:00
|
|
|
if (!removeDirsByFTP(LS_MAILDIR_FTP_HOST,LS_MAILDIR_FTP_PORT,LS_MAILDIR_FTP_USER,LS_MAILDIR_FTP_PWD,$dir)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('MAILDIR_02');
|
2008-09-09 17:48:07 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return true;
|
2009-01-21 18:08:09 +01:00
|
|
|
}
|
2009-01-22 16:26:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retourne le chemin distant de la maildir
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $ldapObject L'objet ldap
|
|
|
|
*
|
|
|
|
* @retval string Le chemin distant de la maildir ou false si il y a un problème
|
|
|
|
*/
|
|
|
|
function getMaildirPath($ldapObject) {
|
|
|
|
$dir = getFData(LS_MAILDIR_FTP_MAILDIR_PATH,$ldapObject,'getValue');
|
|
|
|
|
|
|
|
if (LS_MAILDIR_FTP_MAILDIR_PATH_REGEX != "") {
|
|
|
|
if (ereg(LS_MAILDIR_FTP_MAILDIR_PATH_REGEX,$dir,$regs)) {
|
|
|
|
$dir = $regs[1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$dir = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($dir=="") {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('MAILDIR_04');
|
2009-01-22 16:26:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $dir;
|
|
|
|
}
|
2009-01-21 18:08:09 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Rename Maildir via FTP
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
|
|
|
* @param[in] $old L'ancien chemin de la maildir
|
|
|
|
* @param[in] $new Le nouveau chemin de la maildir
|
|
|
|
*
|
|
|
|
* @retval string True ou false si il y a un problème durant le renomage de la Maildir
|
|
|
|
*/
|
|
|
|
function renameMaildirByFTP($old,$new) {
|
|
|
|
if (!renameDirByFTP(LS_MAILDIR_FTP_HOST,LS_MAILDIR_FTP_PORT,LS_MAILDIR_FTP_USER,LS_MAILDIR_FTP_PWD,$old,$new)) {
|
2009-01-24 18:45:14 +01:00
|
|
|
LSerror :: addErrorCode('MAILDIR_03');
|
2009-01-21 18:08:09 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return true;
|
2008-09-09 17:48:07 +02:00
|
|
|
}
|