2 /*******************************************************************************
3 * Copyright (C) 2007 Easter-eggs
4 * http://ldapsaisie.labs.libre-entreprise.org
6 * Author: See AUTHORS file in top-level directory.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ******************************************************************************/
26 LSerror :: defineError('MAILDIR_SUPPORT_01',
27 _("MAILDIR Support : Unable to load LSaddon::FTP.")
29 LSerror :: defineError('MAILDIR_SUPPORT_02',
30 _("MAILDIR Support : The constant %{const} is not defined.")
34 LSerror :: defineError('MAILDIR_01',
35 _("MAILDIR : Error creating maildir on the remote server.")
37 LSerror :: defineError('MAILDIR_02',
38 _("MAILDIR : Error deleting the maildir on the remote server.")
40 LSerror :: defineError('MAILDIR_03',
41 _("MAILDIR : Error renaming the maildir on the remote server.")
43 LSerror :: defineError('MAILDIR_04',
44 _("MAILDIR : Error retrieving remote path of the maildir.")
48 * Verification du support Maildir par ldapSaisie
50 * @author Benjamin Renard <brenard@easter-eggs.com>
52 * @retval boolean true si Maildir est pleinement supporté, false sinon
54 function LSaddon_maildir_support() {
57 // Dependance de librairie
58 if (!function_exists('createDirsByFTP')) {
59 if(!LSsession :: loadLSaddon('ftp')) {
60 LSerror :: addErrorCode('MAILDIR_SUPPORT_01');
65 $MUST_DEFINE_CONST= array(
66 'LS_MAILDIR_FTP_HOST',
67 'LS_MAILDIR_FTP_USER',
68 'LS_MAILDIR_FTP_MAILDIR_PATH',
69 'LS_MAILDIR_FTP_MAILDIR_PATH_REGEX'
72 foreach($MUST_DEFINE_CONST as $const) {
73 if ( (!defined($const)) || (constant($const) == "")) {
74 LSerror :: addErrorCode('MAILDIR_SUPPORT_02',$const);
82 * Creation d'une Maildir via FTP
84 * @author Benjamin Renard <brenard@easter-eggs.com>
86 * @param[in] $ldapObject L'objet ldap
87 * @param[in] $dir Le chemin de la maildir. Si défini, la valeur ne sera pas
88 * récupérée dans le ldapObject
90 * @retval string True ou false si il y a un problème durant la création de la Maildir
92 function createMaildirByFTP($ldapObject,$dir=null) {
94 $dir = getMaildirPath($ldapObject);
104 if (!createDirsByFTP(LS_MAILDIR_FTP_HOST,LS_MAILDIR_FTP_PORT,LS_MAILDIR_FTP_USER,LS_MAILDIR_FTP_PWD,$dirs,LS_MAILDIR_FTP_MAILDIR_CHMOD)) {
105 LSerror :: addErrorCode('MAILDIR_01');
112 * Suppression d'une Maildir via FTP
114 * @author Benjamin Renard <brenard@easter-eggs.com>
116 * @param[in] $ldapObject L'objet ldap
117 * @param[in] $dir Le chemin de la maildir. Si défini, la valeur ne sera pas
118 * récupérée dans le ldapObject
120 * @retval string True ou false si il y a un problème durant la suppression de la Maildir
122 function removeMaildirByFTP($ldapObject,$dir=null) {
124 $dir = getMaildirPath($ldapObject);
129 if (!removeDirsByFTP(LS_MAILDIR_FTP_HOST,LS_MAILDIR_FTP_PORT,LS_MAILDIR_FTP_USER,LS_MAILDIR_FTP_PWD,$dir)) {
130 LSerror :: addErrorCode('MAILDIR_02');
137 * Retourne le chemin distant de la maildir
139 * @author Benjamin Renard <brenard@easter-eggs.com>
141 * @param[in] $ldapObject L'objet ldap
143 * @retval string Le chemin distant de la maildir ou false si il y a un problème
145 function getMaildirPath($ldapObject) {
146 $dir = getFData(LS_MAILDIR_FTP_MAILDIR_PATH,$ldapObject,'getValue');
148 if (LS_MAILDIR_FTP_MAILDIR_PATH_REGEX != "") {
149 if (ereg(LS_MAILDIR_FTP_MAILDIR_PATH_REGEX,$dir,$regs)) {
158 LSerror :: addErrorCode('MAILDIR_04');
166 * Rename Maildir via FTP
168 * @author Benjamin Renard <brenard@easter-eggs.com>
170 * @param[in] $old L'ancien chemin de la maildir
171 * @param[in] $new Le nouveau chemin de la maildir
173 * @retval string True ou false si il y a un problème durant le renomage de la Maildir
175 function renameMaildirByFTP($old,$new) {
176 if (!renameDirByFTP(LS_MAILDIR_FTP_HOST,LS_MAILDIR_FTP_PORT,LS_MAILDIR_FTP_USER,LS_MAILDIR_FTP_PWD,$old,$new)) {
177 LSerror :: addErrorCode('MAILDIR_03');